Not able connect to EventHub via KAFKA api
Asked Answered
S

4

6

am getting below exception while connecting Event Hub via kafka libraries.

 Caused by: org.apache.kafka.common.protocol.types.SchemaException: Error reading field 'sasl_auth_bytes': Bytes size -1 cannot be negative


ERROR [pool-6-thread-1] STREAM - code="SAE-SP-A-1000: Stream processing failed, exiting ...",exception="Invalid SASL mechanism response, server may be expecting a different protocol"
 org.apache.kafka.common.errors.IllegalSaslStateException: Invalid SASL mechanism response, server may be expecting a different protocol
 Caused by: org.apache.kafka.common.protocol.types.SchemaException: Error reading field 'sasl_auth_bytes': Bytes size -1 cannot be negative
      at org.apache.kafka.common.protocol.types.Schema.read(Schema.java:77) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.common.protocol.ApiKeys.parseResponse(ApiKeys.java:298) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.clients.NetworkClient.parseStructMaybeUpdateThrottleTimeMetrics(NetworkClient.java:687) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.clients.NetworkClient.parseResponse(NetworkClient.java:678) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.common.security.authenticator.SaslClientAuthenticator.receiveKafkaResponse(SaslClientAuthenticator.java:501) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.common.security.authenticator.SaslClientAuthenticator.receiveToken(SaslClientAuthenticator.java:435) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.common.security.authenticator.SaslClientAuthenticator.authenticate(SaslClientAuthenticator.java:259) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.common.network.KafkaChannel.prepare(KafkaChannel.java:173) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.common.network.Selector.pollSelectionKeys(Selector.java:547) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.common.network.Selector.poll(Selector.java:483) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:535) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:265) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:236) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.clients.consumer.internals.ConsumerNetworkClient.poll(ConsumerNetworkClient.java:215) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.clients.consumer.internals.AbstractCoordinator.ensureCoordinatorReady(AbstractCoordinator.java:235) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.clients.consumer.internals.ConsumerCoordinator.poll(ConsumerCoordinator.java:317) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.clients.consumer.KafkaConsumer.updateAssignmentMetadataIfNeeded(KafkaConsumer.java:1226) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1191) ~[kafka-clients-2.2.1.jar!/:?]
      at org.apache.kafka.clients.consumer.KafkaConsumer.poll(KafkaConsumer.java:1176) ~[kafka-clients-2.2.1.jar!/:?]

The consumer properties are as given below:

bootstrap.servers=XXX-topics.servicebus.windows.net:9093
security.protocol=SASL_SSL
sasl.mechanism=PLAIN
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="Endpoint=sb://XXXX-topics.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=**************************";
Study answered 24/1, 2020 at 5:58 Comment(9)
What is the client you are running?Siphonostele
@Serkant Karaca Java code .. client means i didn't get it.Study
I mean which Kafka client and which version? This? mvnrepository.com/artifact/org.apache.kafka/kafka-clients/2.2.1Siphonostele
@Serkant Karaca Its 2.2.1 onlyStudy
Does it fail all the times? I have just tried receiving events with the same Kafka client and it works just fine. Can you share your code?Siphonostele
@Serkant Karaca yes am able to connect now. Issue is in my SharedAccessKey. Thanks for the update.Study
@PonmanikandanBoothalingam I am getting same issue, how did you identified your issue and the fix for it?Miniaturist
is the Eventhub is created in basic tier or standard tier? Check the key in debug weather it come as correct or not.Study
@ChiragVisavadiya its a standard tierStudy
L
17

This error occurs when publishing to a basic plan Event Hub, as the basic plan does not support interaction via Kafka protocol.

https://azure.microsoft.com/de-de/pricing/details/event-hubs/

An upgrade to a standard plan should resolve this.

Lycopodium answered 7/8, 2020 at 10:38 Comment(0)
T
0

You need to additionally use ssl.ca.cert= because you are using SASL_SSL and not SASL_PLAINTEXT. We need to use SASL_SSL to connect to azure event hub.

Terrazas answered 4/12, 2020 at 11:29 Comment(1)
A minor correction, it should be ssl.ca.location.Unvarnished
A
0

Based on the latest Kafka version, this may be the reasons for this exception.

  1. Authentication failed due to invalid credentials with brokers older than 1.0.0
  2. Firewall blocking Kafka TLS traffic (eg it may only allow HTTPS traffic)
  3. Transient network issue. (org.apache.kafka.clients.NetworkClient:759)

In my case the TLS traffic was blocked by the firewall

Antipodes answered 4/1, 2022 at 18:24 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Wendolyn
S
0

For me it was this adding group id like:

bootstrap.servers=<namespace>.servicebus.windows.net:9093
group.id=$Default
request.timeout.ms=60000
security.protocol=SASL_SSL
sasl.mechanism=PLAIN
sasl.jaas.config=org.apache.kafka.common.security.plain.PlainLoginModule required username="$ConnectionString" password="Endpoint=sb://<namespace>.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=<key>";

Slashing answered 23/6, 2022 at 9:46 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.