Kafka OAUTHBEARER: Could not produce message to multiple Event hub namespaces in one application

David Do 1 Reputation point
2022-06-09T05:05:24.447+00:00

Hi experts,

I am using this sample: https://github.com/Azure/azure-event-hubs-for-kafka/tree/master/tutorials/oauth/java/appsecret

I did some minor modifications in TestProducer class (add line 18 and line 26), I want to produce message to 2 different EVENT HUB namespaces (means creating 2 diffrent Kafka Producers for 2 bootstrap servers) in ONE console application, see code:

public class TestProducer {  
    //Change constant to send messages to the desired topic, for this example we use 'test'  
    private final static String TOPIC = "do.kafka.oauth";  
  
    private final static int NUM_THREADS = 1;  
  
  
    public static void main(String... args) throws Exception {  
        //Create Kafka Producer  
        final Producer<Long, String> producer = createProducer(false);  
        final Producer<Long, String> producer_auto = createProducer(true);  
  
        final ExecutorService executorService = Executors.newFixedThreadPool(NUM_THREADS);  
  
        //Run NUM_THREADS TestDataReporters  
        for (int i = 0; i < NUM_THREADS; i++){  
            executorService.execute(new TestDataReporter(producer, TOPIC));  
            executorService.execute(new TestDataReporter(producer_auto, TOPIC));  
        }  
    }  
  
    private static Producer<Long, String> createProducer(boolean isAuto) {  
        try{  
            Properties properties = new Properties();  
            if(isAuto)  
                properties.load(new FileReader("src/main/resources/producer_auto.config"));  
            else  
                properties.load(new FileReader("src/main/resources/producer.config"));  
            properties.put(ProducerConfig.CLIENT_ID_CONFIG, "KafkaExampleProducer");  
            properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, LongSerializer.class.getName());  
            properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());  
            return new KafkaProducer<>(properties);  
        } catch (Exception e){  
            System.out.println("Failed to create producer with exception: " + e);  
            System.exit(0);  
            return null; //unreachable  
        }  
    }  
}  

I attached producer.config and producer_auto.config in this post.

209698-producer.txt
209620-producer-auto.txt

When I execute the code, the application can produce message to just the first namespaces (advantcoeventhubs), and throw exception when produce message to the second namespace (autoeventhubtesting): "ERROR NetworkClient [Producer clientId=KafkaExampleProducer] Connection to node -1 (autoeventhubtesting.servicebus.windows.net/13.66.138.74:9093) failed authentication due to: Invalid SASL mechanism response, server may be expecting a different protocol"

Please see attached picture for error.

209743-invalid-sasl-mechanism-response-server-may-be-expe.png

Can any experts advise the root cause and work around solution?
Thank you so much!

Azure Event Hubs
Azure Event Hubs
An Azure real-time data ingestion service.
675 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. HimanshuSinha-msft 19,476 Reputation points Microsoft Employee
    2022-06-09T22:32:11.797+00:00

    Hello @David Do ,
    Thanks for the question and using MS Q&A platform.

    As we understand the ask here is "Invalid SASL mechanism response, server may be expecting a different protocol" , please do let us know if its not accurate.
    The service bus autoeventhubtersting is this a basic tier ? The basic plan does not interact with Kafka .

    209949-image.png

    Please do let me if you have any queries.
    Thanks
    Himanshu


    • Please don't forget to click on 130616-image.png or upvote 130671-image.png button whenever the information provided helps you. Original posters help the community find answers faster by identifying the correct answer. Here is how
    • Want a reminder to come back and check responses? Here is how to subscribe to a notification
      • If you are interested in joining the VM program and help shape the future of Q&A: Here is how you can be part of Q&A Volunteer Moderators
    0 comments No comments

  2. David Do 1 Reputation point
    2022-06-10T02:42:58.47+00:00

    Hi @HimanshuSinha-msft ,

    210030-standardtier.png

    It was in Standard tier already. It was working successfully when we used a separated application to produce message.
    The issue only happens when we use ONE application to produce message to 2 different event hub namespaces.

    Thank you!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.