Kafka aborting producer batches due to fatal error - spring

I use Spring kafka for my application. It's working perfectly with spring boot version 2.3.2, but when I upgrade to 2.7.0, below error:
2022-05-27 15:32:33.357 "ubuntu1804" "core-service" [main,,] INFO o.a.k.c.producer.KafkaProducer.configureTransactionState:532 - [Producer clientId=producer-1] Instantiated an idempotent producer.
2022-05-27 15:32:33.392 "ubuntu1804" "core-service" [main,,] INFO o.a.k.c.s.a.AbstractLogin.login:61 - Successfully logged in.
2022-05-27 15:32:33.430 "ubuntu1804" "core-service" [main,,] INFO o.a.k.c.utils.AppInfoParser.<init>:119 - Kafka version: 3.0.1
2022-05-27 15:32:33.432 "ubuntu1804" "core-service" [main,,] INFO o.a.k.c.utils.AppInfoParser.<init>:120 - Kafka commitId: 8e30984f43e64d8b
2022-05-27 15:32:33.432 "ubuntu1804" "core-service" [main,,] INFO o.a.k.c.utils.AppInfoParser.<init>:121 - Kafka startTimeMs: 1653640353428
2022-05-27 15:32:34.350 "ubuntu1804" "core-service" [kafka-producer-network-thread | producer-1,,] INFO o.a.kafka.clients.Metadata.update:287 - [Producer clientId=producer-1] Cluster ID: XeVfqn0-QOOFk9uCnDkisw
2022-05-27 15:32:34.354 "ubuntu1804" "core-service" [kafka-producer-network-thread | producer-1,,] INFO o.a.k.c.p.i.TransactionManager.transitionToFatalError:500 - [Producer clientId=producer-1] Transiting to fatal error state due to org.apache.kafka.common.errors.ClusterAuthorizationException: Cluster authorization failed.
2022-05-27 15:32:34.386 "ubuntu1804" "core-service" [kafka-producer-network-thread | producer-1,,] ERROR o.a.k.c.p.internals.Sender.maybeAbortBatches:497 - [Producer clientId=producer-1] Aborting producer batches due to fatal error
org.apache.kafka.common.errors.ClusterAuthorizationException: Cluster authorization failed.
2022-05-27 15:32:34.387 "ubuntu1804" "core-service" [kafka-producer-network-thread | producer-1,,] ERROR o.a.k.c.p.internals.Sender.maybeAbortBatches:497 - [Producer clientId=producer-1] Aborting producer batches due to fatal error
org.apache.kafka.common.errors.ClusterAuthorizationException: Cluster authorization failed.
2022-05-27 15:32:34.388 "ubuntu1804" "core-service" [kafka-producer-network-thread | producer-1,,] ERROR o.a.k.c.p.internals.Sender.maybeAbortBatches:497 - [Producer clientId=producer-1] Aborting producer batches due to fatal error
org.apache.kafka.common.errors.ClusterAuthorizationException: Cluster authorization failed.
Here is my kafka configuration:
spring:
kafka:
producer:
bootstrap-servers: 10.98.0.1:9092,10.98.0.2:9092,10.98.0.3:9092
key-serializer: org.apache.kafka.common.serialization.StringSerializer
value-serializer: org.apache.kafka.common.serialization.StringSerializer
properties:
security:
protocol: SASL_PLAINTEXT
sasl:
mechanism: PLAIN
jaas:
config: org.apache.kafka.common.security.plain.PlainLoginModule required username=${KAFKA_USERNAME:myuser} password=${ENV_KAFKA_PASSWORD:mypassword};
Here is my logging config
logging:
level:
org:
springframework:
web: INFO
apache:
kafka: INFO
When I set logging level to OFF, there is no error anymore. But I just want to know why and how to fix it. Thank you in advance

It may be due to the version of the kafka client, which is not compatible with the kafka broker servion. Change the version of kafka client accordingly.
Other sources
enter link description here

Related

Error sending data to APM even after successful connectivity

Able to establish APM connection
2021-03-09 17:45:05,741 [Attach Listener] INFO co.elastic.apm.agent.configuration.StartupInfo - VM Arguments: [-XX:TieredStopAtLevel=1, -Xmx6g, -Dfile.encoding=UTF-8, -Duser.country=IN, -Duser.language=en, -Duser.variant]
2021-03-09 17:45:08,192 [Attach Listener] INFO co.elastic.apm.agent.impl.ElasticApmTracer - Tracer switched to RUNNING state
2021-03-09 17:45:08,734 [elastic-apm-server-healthcheck] INFO co.elastic.apm.agent.report.ApmServerHealthChecker - Elastic APM server is available: { "build_date": "2021-02-15T12:37:48Z", "build_sha": "e77061bb3aaedae5ae8dd0ca193eb662513aedde", "version": "7.11.0"}
But post connection, it still throws this error. What could be wrong here, appreciate any inputs on this
2021-03-09 17:45:53,484 [elastic-apm-server-reporter] INFO co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Backing off for 0 seconds (+/-10%)
2021-03-09 17:45:53,489 [elastic-apm-server-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Error sending data to APM server: Read timed out, response code is -1
2021-03-09 17:45:53,489 [elastic-apm-server-reporter] WARN co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - null
2021-03-09 17:46:08,890 [elastic-apm-server-reporter] INFO co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Backing off for 1 seconds (+/-10%)
2021-03-09 17:46:09,922 [elastic-apm-server-reporter] ERROR co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - Error sending data to APM server: Read timed out, response code is -1
2021-03-09 17:46:09,922 [elastic-apm-server-reporter] WARN co.elastic.apm.agent.report.IntakeV2ReportingEventHandler - null
Check your kibana.yml file URLs, when I setup APM I my machine some of my URLs (elasticsearch.hosts, xpack.fleet.outputs) were defaulted to my current IP address (instead of localhost), which changed after a reboot.

How to get resolve ElasticSearch warning message "Transport Handler Not Found" on spring boot application console?

We have two Spring boot applications using the same Elasticsearch database. The queries work fine. But the console of the second spring boot application is always flooded with these warning messages as soon as it boots up. Is there any configuration we are missing, either in the Spring boot app or at Elasticsearch?
2021-02-16 16:15:03.757 INFO 19828 --- [main] o.s.d.e.c.TransportClientFactoryBean: Adding transport node : 127.0.0.1:9300
2021-02-16 16:15:04.760 WARN 19828 --- [ient_boss][T#1]] o.e.transport.TransportService: Transport response handler not found of id [1]
2021-02-16 16:15:04.932 WARN 19828 --- [ient_boss][T#2]] o.e.transport.TransportService: Transport response handler not found of id [3]
2021-02-16 16:15:08.104 WARN 19828 --- [ient_boss][T#7]] o.e.transport.TransportService: Transport response handler not found of id [9]
2021-02-16 16:15:13.232 WARN 19828 --- [ient_boss][T#8]] o.e.transport.TransportService: Transport response handler not found of id [59]

Kafka on Mac There are no in-flight requests for node -1 while starting console consumer

I am new to Kafka and trying to install and run console consumer but getting error java.lang.IllegalStateException: There are no in-flight requests for node -1
Environment I tried on is as below
Kafka Version kafka_2.13-2.6.0
MacOS java11 Fails
MacOS java 1.8 Fails
Windows 10 Java11 Success
Below are the steps in details which I am performing. The same steps works on Windows.
STEP 1 Download KAFKA
I just downloaded the Kafka from https://www.apache.org/dyn/closer.cgi?path=/kafka/2.6.0/kafka_2.13-2.6.0.tgz
STEP 2 Start zookeeper service, which works fine.
I am starting zookeeper with below command
bin % zookeeper-server-start.sh ../config/zookeeper.properties
here is the zookeeper log
[2020-08-30 14:28:52,234] INFO Server environment:java.io.tmpdir=/var/folders/q7/khp8p9k14rzfs_zl52m57hlr0000gn/T/ (org.apache.zookeeper.server.ZooKeeperServer)
[2020-08-30 14:28:52,234] INFO Server environment:java.compiler=<NA> (org.apache.zookeeper.server.ZooKeeperServer)
[2020-08-30 14:28:52,234] INFO Server environment:os.name=Mac OS X (org.apache.zookeeper.server.ZooKeeperServer)
[2020-08-30 14:28:52,234] INFO Server environment:os.arch=x86_64 (org.apache.zookeeper.server.ZooKeeperServer)
[2020-08-30 14:28:52,234] INFO Server environment:os.version=10.15.6 (org.apache.zookeeper.server.ZooKeeperServer)
[2020-08-30 14:28:52,234] INFO Server environment:user.name=jigarnaik (org.apache.zookeeper.server.ZooKeeperServer)
[2020-08-30 14:28:52,234] INFO Server environment:user.home=/Users/jigarnaik (org.apache.zookeeper.server.ZooKeeperServer)
[2020-08-30 14:28:52,234] INFO Server environment:user.dir=/Users/jigarnaik/Documents/kafka_2.13-2.6.0/bin (org.apache.zookeeper.server.ZooKeeperServer)
[2020-08-30 14:28:52,234] INFO Server environment:os.memory.free=496MB (org.apache.zookeeper.server.ZooKeeperServer)
[2020-08-30 14:28:52,234] INFO Server environment:os.memory.max=512MB (org.apache.zookeeper.server.ZooKeeperServer)
[2020-08-30 14:28:52,234] INFO Server environment:os.memory.total=512MB (org.apache.zookeeper.server.ZooKeeperServer)
[2020-08-30 14:28:52,235] INFO minSessionTimeout set to 6000 (org.apache.zookeeper.server.ZooKeeperServer)
[2020-08-30 14:28:52,235] INFO maxSessionTimeout set to 60000 (org.apache.zookeeper.server.ZooKeeperServer)
[2020-08-30 14:28:52,236] INFO Created server with tickTime 3000 minSessionTimeout 6000 maxSessionTimeout 60000 datadir /tmp/zookeeper/version-2 snapdir /tmp/zookeeper/version-2 (org.apache.zookeeper.server.ZooKeeperServer)
[2020-08-30 14:28:52,243] INFO Using org.apache.zookeeper.server.NIOServerCnxnFactory as server connection factory (org.apache.zookeeper.server.ServerCnxnFactory)
[2020-08-30 14:28:52,247] INFO Configuring NIO connection handler with 10s sessionless connection timeout, 2 selector thread(s), 32 worker threads, and 64 kB direct buffers. (org.apache.zookeeper.server.NIOServerCnxnFactory)
[2020-08-30 14:28:52,254] INFO binding to port 0.0.0.0/0.0.0.0:2181 (org.apache.zookeeper.server.NIOServerCnxnFactory)
[2020-08-30 14:28:52,268] INFO zookeeper.snapshotSizeFactor = 0.33 (org.apache.zookeeper.server.ZKDatabase)
[2020-08-30 14:28:52,271] INFO Snapshotting: 0x0 to /tmp/zookeeper/version-2/snapshot.0 (org.apache.zookeeper.server.persistence.FileTxnSnapLog)
[2020-08-30 14:28:52,273] INFO Snapshotting: 0x0 to /tmp/zookeeper/version-2/snapshot.0 (org.apache.zookeeper.server.persistence.FileTxnSnapLog)
[2020-08-30 14:28:52,286] INFO Using checkIntervalMs=60000 maxPerMinute=10000 (org.apache.zookeeper.server.ContainerManager)
load: 1.58 cmd: java 17764 waiting 0.68u 0.11s
STEP 3 start Kafka - the logs look fine to me.
After that I am starting Kafka using below command
bin % kafka-server-start.sh ../config/server.properties
Kafka startup looks fine with below log tail
[2020-08-30 14:33:41,708] INFO [TransactionCoordinator id=0] Starting up. (kafka.coordinator.transaction.TransactionCoordinator)
[2020-08-30 14:33:41,709] INFO [Transaction Marker Channel Manager 0]: Starting (kafka.coordinator.transaction.TransactionMarkerChannelManager)
[2020-08-30 14:33:41,709] INFO [TransactionCoordinator id=0] Startup complete. (kafka.coordinator.transaction.TransactionCoordinator)
[2020-08-30 14:33:41,728] INFO [ExpirationReaper-0-AlterAcls]: Starting (kafka.server.DelayedOperationPurgatory$ExpiredOperationReaper)
[2020-08-30 14:33:41,757] INFO [/config/changes-event-process-thread]: Starting (kafka.common.ZkNodeChangeNotificationListener$ChangeEventProcessThread)
[2020-08-30 14:33:41,770] INFO [SocketServer brokerId=0] Starting socket server acceptors and processors (kafka.network.SocketServer)
[2020-08-30 14:33:41,773] INFO [SocketServer brokerId=0] Started data-plane acceptor and processor(s) for endpoint : ListenerName(PLAINTEXT) (kafka.network.SocketServer)
[2020-08-30 14:33:41,773] INFO [SocketServer brokerId=0] Started socket server acceptors and processors (kafka.network.SocketServer)
[2020-08-30 14:33:41,775] INFO Kafka version: 2.6.0 (org.apache.kafka.common.utils.AppInfoParser)
[2020-08-30 14:33:41,775] INFO Kafka commitId: 62abe01bee039651 (org.apache.kafka.common.utils.AppInfoParser)
[2020-08-30 14:33:41,775] INFO Kafka startTimeMs: 1598769221773 (org.apache.kafka.common.utils.AppInfoParser)
[2020-08-30 14:33:41,776] INFO [KafkaServer id=0] started (kafka.server.KafkaServer)
[2020-08-30 14:33:41,808] INFO [ReplicaFetcherManager on broker 0] Removed fetcher for partitions Set(word-count-output-0, word-count-input-0) (kafka.server.ReplicaFetcherManager)
[2020-08-30 14:33:41,815] INFO [Partition word-count-output-0 broker=0] Log loaded for partition word-count-output-0 with initial high watermark 0 (kafka.cluster.Partition)
[2020-08-30 14:33:41,821] INFO [Partition word-count-input-0 broker=0] Log loaded for partition word-count-input-0 with initial high watermark 0 (kafka.cluster.Partition)
STEP 4 Create topic, topic created successfully.
after which I. am creating topic
bin % kafka-topics.sh \
--create \
--zookeeper localhost:2181 \
--replication-factor 1 \
--partitions 1 \
--topic my-topic
Created topic my-topic.
list topic
bin % kafka-topics.sh \
--list \
--zookeeper localhost:2181
my-topic
word-count-input
word-count-output
STEP 5 Run console producer, fails with below error.
but when I try to start the console producer using below command, I am getting exception java.lang.IllegalStateException: There are no in-flight requests for node -1 The same step when I run on windows it works fine, I am getting issue only on Mac.
bin % kafka-console-producer.sh \
--topic word-count-input \
--bootstrap-server localhost:9092
>[2020-08-30 14:35:17,902] ERROR [Producer clientId=console-producer] Uncaught error in kafka producer I/O thread: (org.apache.kafka.clients.producer.internals.Sender)
java.nio.BufferUnderflowException
at java.nio.Buffer.nextGetIndex(Buffer.java:509)
at java.nio.HeapByteBuffer.getInt(HeapByteBuffer.java:364)
at org.apache.kafka.common.protocol.ByteBufferAccessor.readInt(ByteBufferAccessor.java:43)
at org.apache.kafka.common.message.ResponseHeaderData.read(ResponseHeaderData.java:102)
at org.apache.kafka.common.message.ResponseHeaderData.<init>(ResponseHeaderData.java:70)
at org.apache.kafka.common.requests.ResponseHeader.parse(ResponseHeader.java:66)
at org.apache.kafka.clients.NetworkClient.parseStructMaybeUpdateThrottleTimeMetrics(NetworkClient.java:717)
at org.apache.kafka.clients.NetworkClient.handleCompletedReceives(NetworkClient.java:834)
at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:553)
at org.apache.kafka.clients.producer.internals.Sender.runOnce(Sender.java:325)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:240)
at java.lang.Thread.run(Thread.java:748)
[2020-08-30 14:35:17,904] ERROR [Producer clientId=console-producer] Uncaught error in kafka producer I/O thread: (org.apache.kafka.clients.producer.internals.Sender)
java.lang.IllegalStateException: There are no in-flight requests for node -1
at org.apache.kafka.clients.InFlightRequests.requestQueue(InFlightRequests.java:62)
at org.apache.kafka.clients.InFlightRequests.completeNext(InFlightRequests.java:70)
at org.apache.kafka.clients.NetworkClient.handleCompletedReceives(NetworkClient.java:833)
at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:553)
at org.apache.kafka.clients.producer.internals.Sender.runOnce(Sender.java:325)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:240)
at java.lang.Thread.run(Thread.java:748)
[2020-08-30 14:35:17,938] ERROR Uncaught exception in thread 'kafka-producer-network-thread | console-producer': (org.apache.kafka.common.utils.KafkaThread)
java.lang.OutOfMemoryError: Java heap space
at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:57)
at java.nio.ByteBuffer.allocate(ByteBuffer.java:335)
at org.apache.kafka.common.memory.MemoryPool$1.tryAllocate(MemoryPool.java:30)
at org.apache.kafka.common.network.NetworkReceive.readFrom(NetworkReceive.java:113)
at org.apache.kafka.common.network.KafkaChannel.receive(KafkaChannel.java:447)
at org.apache.kafka.common.network.KafkaChannel.read(KafkaChannel.java:397)
at org.apache.kafka.common.network.Selector.attemptRead(Selector.java:678)
at org.apache.kafka.common.network.Selector.pollSelectionKeys(Selector.java:580)
at org.apache.kafka.common.network.Selector.poll(Selector.java:485)
at org.apache.kafka.clients.NetworkClient.poll(NetworkClient.java:544)
at org.apache.kafka.clients.producer.internals.Sender.runOnce(Sender.java:325)
at org.apache.kafka.clients.producer.internals.Sender.run(Sender.java:240)
at java.lang.Thread.run(Thread.java:748)
Finally I found the issue, the port was being used by sonarqube running on my local but surprisingly when I started kafka there was no error reported.
Honestly, I don't know how Firewall/Antivirus played some role but somehow its linked to this problem.
In my case, Consumer was able to consume messages only once but it throws exception BufferUnderflowException when I started the consumer again.
Turning-Off Firewall/Antivirus was't option for me so I added/enabled advertised.listeners=PLAINTEXT://localhost:9092 configuration in server.properties of kafka-server and afterwards it works as expected.
kafka version: 2.6.0
My norton antivirus firewall settings was causing this issue. I disabled firewall settings and everything started working fine.
I got the same issue. It was happening because sonarqube uses a second port 9092. To avoid this, I suggest to use the sonarqube docker image instead of downloading locally.

Disabled ZooKeeper in bootstrap.yml, it still runs during testing

I am running a SpringBoot App. I have bootstrap-test.yml (located under src/test/resources/config), which looks like:
spring.cloud.config.enabled: false
spring.cloud.service-registry.auto-registration.enabled: false
spring.cloud.zookeeper.discovery.enabled: false
spring.cloud.zookeeper.discovery.register: false
pom:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
<version>2.2.2.RELEASE</version>
</dependency>
However, when I try to run an integration test:
#ActiveProfiles("test")
#DirtiesContext
#SpringBootTest
public class TestClass......
ZooKeeper still attempts to connect "live":
16:02:14.752 [main] INFO org.apache.zookeeper.ZooKeeper - Client environment:os.memory.free=493MB
16:02:14.752 [main] INFO org.apache.zookeeper.ZooKeeper - Client environment:os.memory.max=8116MB
16:02:14.752 [main] INFO org.apache.zookeeper.ZooKeeper - Client environment:os.memory.total=610MB
16:02:14.778 [main] INFO o.a.c.f.imps.CuratorFrameworkImpl - Starting
16:02:14.783 [main] INFO org.apache.zookeeper.ZooKeeper - Initiating client connection, connectString=localhost:2181 sessionTimeout=60000 watcher=org.apache.curator.ConnectionState#76d828ff
16:02:14.788 [main] INFO o.apache.zookeeper.ClientCnxnSocket - jute.maxbuffer value is 4194304 Bytes
16:02:14.798 [main-SendThread(localhost:2181)] INFO org.apache.zookeeper.ClientCnxn - Opening socket connection to server localhost/0:0:0:0:0:0:0:1:2181. Will not attempt to authenticate using SASL (unknown error)
16:02:14.805 [main] INFO o.a.c.f.imps.CuratorFrameworkImpl - Default schema
16:02:16.805 [main-SendThread(localhost:2181)] WARN org.apache.zookeeper.ClientCnxn - Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect
java.net.ConnectException: Connection refused: no further information
at java.base/sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:779)
at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:357)
at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1214)
I want to disable all zookeeper bootstrap actions for integration test. What gives, I'm frustrated and have no idea what is wrong: why is Zookeeper still trying to run when I disabled it? Thanks in advance.
this should work !
spring.cloud.zookeeper.enabled=false
for yaml,
spring:
cloud:
zookeeper:
enabled: false

Kafka on Google Cloud Platform Integration with Spring Boot

I am running Kafka on GCP and sending message to Topic from Spring Boot App.
In GCP consumer window, messages are not getting displayed.
I have allowed all firewall access to my VM which is running Kafka.
Any thoughts??
Exception in spring IDE console
2018-10-10 00:25:06.819 INFO 4472 --- [nio-8080-exec-1]
o.a.kafka.common.utils.AppInfoParser : Kafka version : 1.0.2
2018-10-10 00:25:06.820 INFO 4472 --- [nio-8080-exec-1]
o.a.kafka.common.utils.AppInfoParser : Kafka commitId :
2a121f7b1d402825
2018-10-10 00:25:38.158 ERROR 4472 --- [ad | producer-1]
o.s.k.support.LoggingProducerListener : Exception thrown when
sending a message with key='null' and payload='888' to topic test:
org.apache.kafka.common.errors.TimeoutException: Expiring 1 record(s)
for test-0: 30034 ms has passed since batch creation plus linger time .

Resources