Skip to content

org.apache.kafka.common.errors.TimeoutException: Topic my-topic-processing not present in metadata after 60000 m

1

I have a MSK cluster in same VPC in which my EKS Kubernates services are running . on both sides ( MSK and EKS) Security groups are updated to allow traffic.

I am using Spring boot Kafka Library to publish messages to Kafka Topic and retrieve the response metadata using following codes. I am getting error as "org.apache.kafka.common.errors.TimeoutException: Topic my-topic-processing not present in metadata after 60000 m" while publishing the messages.

Application.Yaml kafka: bootstrap-url: bootstrap-servers: b-1.<cluster>.c2.kafka.<region>.amazonaws.com:9092 producer: acks: 1 properties: linger.ms: 5 retry.backoff.ms: 100 buffer.memory: 134217728 request.timeout.ms: 10000 delivery.timeout.ms: 30000

public void send(final @NonNull String topic, final @NonNull Map<String, String> headers, final @NonNull String data) { var producerRecord = new ProducerRecord<String, String>(topic, data);

final long startTime = System.currentTimeMillis(); final CompletableFuture<SendResult<String, String>> future = kafkaTemplate.send(producerRecord);

future.whenCompleteAsync((result, ex) -> { long elapsedTime = System.currentTimeMillis() - startTime; if (ex != null) { log.error("Failed to send message to topic {}: {}", result.getRecordMetadata().topic(), ex.getMessage()); } else { log.info("Sent message to topic {} partition {} with offset {} in {} ms", result.getRecordMetadata().topic(), result.getRecordMetadata().partition(), result.getRecordMetadata().offset(), elapsedTime); } }); }

Am i Missing any configuration in MSK to fetch the topic metadata?

3 Answers
0

The error "org.apache.kafka.common.errors.TimeoutException: Topic my-topic-processing not present in metadata after 60000 ms" indicates that your Spring Boot application is trying to publish messages to a topic that doesn't exist in your MSK cluster.

Here are some steps to resolve this issue:

  1. First, make sure the topic "my-topic-processing" actually exists in your MSK cluster. You need to create the topic before publishing messages to it. You can create a topic using the Kafka CLI tools:
kafka-topics.sh --create --topic my-topic-processing --bootstrap-server b-1.<cluster>.c2.kafka.<region>.amazonaws.com:9092 --partitions 3 --replication-factor 2
  1. Check your connectivity between your EKS cluster and MSK:
  • Verify that the security groups are properly configured to allow traffic on port 9092 (or the appropriate port you're using).
  • Ensure that your EKS pods can reach the MSK brokers. You can test this by running a simple network connectivity test from within a pod.
  1. Review your Kafka client configuration:
  • Your bootstrap-servers configuration looks correct, but make sure you're using the right protocol (9092 for plaintext, 9094 for TLS, 9098 for IAM authentication).
  • If your MSK cluster uses IAM authentication, you'll need additional configuration properties like:
security.protocol=SASL_SSL
sasl.mechanism=AWS_MSK_IAM
sasl.jaas.config=software.amazon.msk.auth.iam.IAMLoginModule required;
sasl.client.callback.handler.class=software.amazon.msk.auth.iam.IAMClientCallbackHandler
  • You'll also need to include the aws-msk-iam-auth JAR in your classpath.
  1. Consider increasing the timeout values in your configuration if network latency is an issue:
request.timeout.ms: 30000
metadata.max.age.ms: 300000
  1. Enable more detailed logging for the Kafka client to get better insights into the connection issues.

Once you've created the topic and ensured proper connectivity between your EKS cluster and MSK, the timeout error should be resolved.
Sources
Help me troubleshoot this problem. | AWS re:Post
msk connector not able to fetchdata from msk cluster.. timeout error INFO [AdminClient clientId=adminclient-1] Metadata update failed (org.apache.kafka.clients.admin.internals.AdminMetadataManager:23 | AWS re:Post

answered 10 months ago

  • I checked the MSK configuration as you suggested, seems to be configured correctly. If i removed the Spring producers custom configuration, the kafkatemplate able publish the message to topic with default configuration. We are seeing some high latency while publishing message and reduce the latency with custom configuration with batching.

    Please suggest if any configuration are missing?

0

The error depicts that the producer cannot find the topic using the provided Kafka configuration. The topic may exist, but the producer cannot access it due to authentication, connectivity, or partition mismatch. Mismatch in the partitions : the partition of the topic that the client is trying to write to does not exits. Furthermore, this issue may arise due to a version mismatch between the Kafka client dependency and the Spring Boot version being used. [+] https://spring.io/projects/spring-kafka.

Consider modifying the below setting in the custom configurations -

set the below to default values:

request.timeout.ms: 30000 
delivery.timeout.ms: 120000

Additionally,

metadata.max.idle.ms: 60000
metadata.max.age.ms: 60000

For Latency issues consider increasing the batch.size which defines the maximum number of bytes that will be included in one batch and fine tune the linger.ms - to control the amount of time a producer waits for a batch to fill. Smaller batches are computationally expensive for Kafka as they translate to more threads and I/O operations at once. [+] https://docs.aws.amazon.com/msk/latest/developerguide/bestpractices-kafka-client.html#bestpractices-kafka-client-performance

Additionally, try increasing partition count for the topic and then monitor your cluster heath and the partition count per broker [+] https://docs.aws.amazon.com/msk/latest/developerguide/metrics-details.html

If you are encountering the same issue after verifying the above details, please reach out to us via support case so that we will be able to investigate the issue further.

AWS

answered 10 months ago

  • Thank you for sharing the insights.

    Below is our current setup and configuration:

    Environment

    AWS Managed Kafka (MSK), provisioned cluster

    MSK Kafka version: 3.5.1 Spring Boot version: 3.5.0 Kafka client version: 3.9.1

    Here is my spring kafka configuration

    kafka: bootstrap-servers: ${spring.kafka.bootstrap} producer: acks: 1 properties: linger.ms: 25 batch.size: 131072 buffer.memory: 67108864 request.timeout.ms: 30000 delivery.timeout.ms: 120000 metadata.max.idle.ms: 60000 metadata.max.age.ms: 60000 compression.type: zstd send.buffer.bytes: -1

    We followed the AWS MSK client performance tuning recommendations outlined here: https://docs.aws.amazon.com/msk/latest/developerguide/bestpractices-kafka-client.html#bestpractices-kafka-client-performance

    Despite applying these recommendations and tuning the producer parameters, we are still encountering the following timeout error:

    org.apache.kafka.common.errors.TimeoutException: Expiring 87 record(s) for task-executing-0:120195 ms has passed since batch creation.

    Could you please recommend possible causes and resolutions for this issue?

0

The timeout means the Kafka producer can’t get metadata for the topic, which usually happens when the brokers aren’t reachable or the topic doesn’t exist. In MSK, brokers advertise their private DNS names, so your EKS pods must resolve and connect to those endpoints within the same VPC. Verify that your EKS cluster nodes’ security group allows outbound TCP 9092 and that the MSK security group allows inbound TCP 9092 from the EKS group. Confirm the topic exists by running aws kafka list-topics --cluster-arn <your-cluster-arn> or using a Kafka client with --list. If it’s missing, create it using `kafka-topics. —Taz

answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.