Kafka Console Producer sending message failed - apache-kafka

I would like to ask anyone face before this kind of stuation?
Few days ago the kafka is able to work properly but today it starting having problem. The console producer is unable to send message and receive by console consumer. After few seconds it prompt :
" ERROR Error when sending message to topic test with key: null, value: 11 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
org.apache.kafka.common.errors.TimeoutException: Failed to update metadata after 60000 ms. "
Anyone can help? :'(

You'll see this if the broker you are bootstrapping from is not reachable. Try to telnet to the host and port you are trying to access from the producer. If that communication is OK, turn on debug logging by locating the tools-log4j.properties and changing the warn level to debug.

Related

Kafka issue in kubernetes

When any message push to Kafka topic i'm seeing below message.
my message contains only 5 elements and it is plain text only it wont exceed 300 characters still seeing below error.
WARN [SocketServer brokerId=0] Unexpected error from /127.0.0.1; closing connection (org.apache.kafka.common.network.Selector)
org.apache.kafka.common.network.InvalidReceiveException: Invalid receive (size = 1920298859 larger than 504857600)
at org.apache.kafka.common.network.NetworkReceive.readFrom(NetworkReceive.java:104)
at org.apache.kafka.common.network.KafkaChannel.receive(KafkaChannel.java:381)
at org.apache.kafka.common.network.KafkaChannel.read(KafkaChannel.java:342)
at org.apache.kafka.common.network.Selector.attemptRead(Selector.java:609)
at org.apache.kafka.common.network.Selector.pollSelectionKeys(Selector.java:541)
at org.apache.kafka.common.network.Selector.poll(Selector.java:467)
at kafka.network.Processor.poll(SocketServer.scala:689)
at kafka.network.Processor.run(SocketServer.scala:594)
at java.lang.Thread.run(Thread.java:748)
If no active consumer for long time around 8 to 10 hours kafka itself killing in Kubernetes.
I want some good article to setup Kafka cluster in Kubernetes any help appreciated.
1920298859 is a recognizable value, it's ruok decoded as a integer:
>>> struct.unpack("!I", struct.pack("!4s", "ruok".encode("UTF8")))
(1920298859,)
It looks like you have some Zookeeper tooling/healthcheck trying to connect to Kafka. The ruok command should only be sent to Zookeeper hosts. Kafka only accepts connections from Kafka clients.

Kakfa retries Concept - What Basis retries will be stopped in Kafka?

As am new to Kafka , trying to understand the retries concept in Kafka . What basis retries process will be completed ?
Example Retries parameter we set as 7 . Now questions here ,
Kafka will be retried in all 7 times ?
Will be tried until successful process ? If so , How Kafka will come to know about successful ?
If that would be depends upon any parameter what Is that parameter and how ?
In distributed systems, retries are inevitable. From network errors to replication issues and even outages in downstream dependencies, services operating at a massive scale must be prepared to encounter, identify, and handle failure as gracefully as possible.
Kafka will retry until the initiated process is successfully completed or retry count is zero.
Kafka maintains the status of each API call ( producer , consumer, and Streams ), and if the error condition meets then retry count is decreased.
Please go through the completeBatch function of the Sender.java in the following URL to get more information.
https://github.com/apache/kafka/blob/68ac551966e2be5b13adb2f703a01211e6f7a34b/clients/src/main/java/org/apache/kafka/clients/producer/internals/Sender.java
I guess you are talking about producer retrying to send failed messages.
From kafka producer retries property documentation -
"Setting a value greater than zero will cause the client to resend any
record whose send fails with a potentially transient error."
This means that kafka producer will retry if the error it encountered is considered "Retriable". not all errors are retriable - for example, if the target kafka topic does not exist, theres no point in trying to send the message again.
but if for example the connection was interrupted, it makes sense to try again.
Important to note - retries are only relevant if you have set broker ack != 0.
So, in your example you have 7 retries configured.
I assume that ack is set to a value different than 0 because then no retries will be attempted.
If your message failed with a non-retriable error, Kafka producer will not try to send the message again (it will actually 'give-up' on that message and move on to next messages).
If your message failed with a retriable error, Kafka producer will retry sending until message is successfully sent, or until retries are exhausted (when 7 retries were attempted and none of them succeeded).
Kafka client producer knows when your message was successfully sent to broker because when ack is set to 1\all, the kafka broker is "Acknowledging" any message received and informs the producer (in a kind of handshake between the producer and broker).
see acks & retries # https://kafka.apache.org/documentation/#producerconfigs
Kafka reties happens for transient exceptions such as NotEnoughReplicaException.
In Kafka version <=2.0 default retry is 0.
In Kafka version > 2.0 default retry is Integer.MAX
From kafka 2.1 retries are bounded to timeouts, there are couple of producer configuration such as.
delivery.timeout.ms=120000ms - by default producer will retry for 2 mins, if retry is not successful after 2 mins the request will not send to broker and we have to handle manually.
retry.backoff.ms=100ms - by default every 100ms producer will retry till delivery.timeout reaches.

Error in kafka when consumed by a remote client

Kafka already work good in the localhost as consumer but, when i make a consumer in a remote machine I get the next error:
[2020-02-06 11:53:22,172] ERROR Error when sending message to topic TopicTest with key: null, value: 4 bytes with error: (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
org.apache.kafka.common.errors.TimeoutException: Expiring 1 record(s) for TopicTest-0: 2325 ms has passed since batch creation plus linger time
The conection between the remote machine and the server is fine because i execute the next command and work:
bin/kafka-topics.sh --list --zookeeper my.public.ip:2181
You should check advertised.listeners config in server.properties. If it is localhost, then you should change it to broker ip address. This answer can also helpful for you.

Batch containing 1 record(s) expired due to timeout while requesting metadata from brokers for test-0

today a message prompt out when I try to send message to consumer console through producer console
[2016-11-02 15:12:58,168] ERROR Error when sending message to topic test with
key: null, value: 5 bytes with error:
(org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
org.apache.kafka.common.errors.TimeoutException: Batch containing 1 record(s)
expired due to timeout while requesting metadata from brokers for test-0
Why is this happened? Is this consider as Kafka problem or Zookeeper problem?
Seems that client failed to retrieve metadata for test-0 from the kafka brokers.
Either make sure you are able to connect to the kafka brokers or check if 'advertised.listeners' is set if you are running kafka on IaaS machines.
Well after I rebooted the whole server the problem is gone.

Trouble changing port in Confluent 2.0.0 Kafka 0.9

Seeing some strange behavior with Confluent 2.0.0 Kafka 0.9, wondering if anyone has any ideas. I had started up a broker with the PLAINTEXT listener, on 9092. worked great. I am trying to change it to listen to a different port. I tried 9095. When it starts up I see this in the log:
[2016-01-14 18:11:43,511] INFO Awaiting socket connections on 0.0.0.0:9095. (kafka.network.Acceptor)
But then later, I see this
[2016-01-14 18:11:43,906] INFO Registered broker 0 at path /brokers/ids/0 with addresses: PLAINTEXT -> EndPoint(ec2-54-164-3-183.compute-1.amazonaws.com,9092,PLAINTEXT) (kafka.utils.ZkUtils)
This is concerning, why is it still registering on 9092???
At this point, if I try to produce on 9095 I get tons of these until I kill it:
[2016-01-14 18:14:42,614] WARN Error while fetching metadata with correlation id 0 : {plaintext=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
[2016-01-14 18:14:42,745] WARN Error while fetching metadata with correlation id 1 : {plaintext=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
[2016-01-14 18:14:42,850] WARN Error while fetching metadata with correlation id 2 : {plaintext=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
...
And if I try to produce on 9092 it fails after 1 minute with this:
[2016-01-14 18:30:11,845] ERROR Error when sending message to topic plaintext with key: null, value: 10 bytes with error: Failed to update metadata after 60000 ms. (org.apache.kafka.clients.producer.internals.ErrorLoggingCallback)
I think this may have something to do with my host names not being set up properly... but I'm not sure how to do that... FYI this is an EC2 instance. hostname is ip-10-0-0-22. /etc/hosts has
127.0.0.1 localhost
The public DNS is ec2-54-164-3-183.compute-1.amazonaws.com. And in my server.properties I have
advertised.host.name=ec2-54-164-3-183.compute-1.amazonaws.com
(This last I found I had to set to be able to connect to the broker from outside of amazon).
So... any suggestions from any Kafka experts?
There's advertised.port property which you can explicitly set to 9095.
Turns out I needed to use advertised.listeners. I bet Alexander Zolotko's suggestion to use advertised.port would have worked too, although I didn't try tat.