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

David Do 1 Reputation point

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) {  
            Properties properties = new Properties();  
                properties.load(new FileReader("src/main/resources/producer_auto.config"));  
                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);  
            return null; //unreachable  

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


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/ failed authentication due to: Invalid SASL mechanism response, server may be expecting a different protocol"

Please see attached picture for error.


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.
380 questions
No comments
{count} votes

2 answers

Sort by: Oldest
  1. HimanshuSinha-msft 18,366 Reputation points Microsoft Employee

    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 .


    Please do let me if you have any queries.

    • 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
  2. David Do 1 Reputation point

    Hi @HimanshuSinha-msft ,


    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!