question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Timeout on ProduceAsync depending on the topic

See original GitHub issue

Description

Hi, When I produce a message to a Kafka topic, if I doesn’t use the “test-topic” topic (default ?) I finally get a Timeout. If I do use the test-topic" topic name everything works fine.

Is there any missing configuration on my topics to accept published message ?

How to reproduce

This is perfectly working

            var config = new ProducerConfig { BootstrapServers = "kafka:9092" };

            using (var p = new ProducerBuilder<Null, string>(config).Build())
            {
                try
                {

                    var strMessage = JsonConvert.SerializeObject(message);
                    var dr = await p.ProduceAsync("test-topic", new Message<Null, string> { Value = strMessage });  
                    Console.WriteLine($"Delivered '{dr.Value}' to '{dr.TopicPartitionOffset}'");
                }
                catch (ProduceException<Null, string> e)
                {
                    Console.WriteLine($"Delivery failed: {e.Error.Reason}");
                }
            }

This is throwing an exception after a long timeout (note I only changed the topic name to “test1” that does exists)

            var config = new ProducerConfig { BootstrapServers = "kafka:9092" };

            using (var p = new ProducerBuilder<Null, string>(config).Build())
            {
                try
                {

                    var strMessage = JsonConvert.SerializeObject(message);
                    var dr = await p.ProduceAsync("test1", new Message<Null, string> { Value = strMessage });  
                    Console.WriteLine($"Delivered '{dr.Value}' to '{dr.TopicPartitionOffset}'");
                }
                catch (ProduceException<Null, string> e)
                {
                    Console.WriteLine($"Delivery failed: {e.Error.Reason}");
                }
            }

This is the exception image

My docker-compose configuration

  zookeeper:
    image: wurstmeister/zookeeper
    container_name: zookeeper
    ports:
      - "2181:2181"

  kafka:
    image: wurstmeister/kafka
    container_name: kafka
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: kafka
      KAFKA_CREATE_TOPICS: "test1:1:1"
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

Here are the list of topics inside my kafka container image

Both “topic-test” and “test1” exist

Checklist

Please provide the following information:

  • A complete (i.e. we can run it), minimal program demonstrating the problem. No need to supply a project file.

  • Confluent.Kafka nuget version. v 1.4.3

  • Apache Kafka version. 2.12-2.2.0 from https://microbadger.com/images/wurstmeister/kafka

  • Client configuration. .net core 3.1

  • Operating system. Windows 10 Pro with Docker Desktop 2.3.0.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mhowlettcommented, Jun 9, 2020

with the default broker settings, topics are created on the fly (but generally this isn’t good practice and you should turn it off).

a leader is the partition replica that is produced/consumed from, all other replicas (in most cases) are just there to provide redundancy.

somehow you have 1001 replicas, and no leader. something is very wrong on the broker.

I’d recommend reading some introductory material on kafka to get the fundamentals

0reactions
NicolasReyDotNetcommented, Jun 9, 2020

@mhowlett I finally rebooted my cpu, everything works fine now : topics are indeed created on the fly (fine for dev env) and all topics have a leader, the Produce operation with your lib works like a charm! Thank you

Read more comments on GitHub >

github_iconTop Results From Across the Web

Net Core Kafka ProduceAsync doesn't complete
I've found some code through research that has had the best success, but now it seems to have trouble when implementing a .ProduceAsync()...
Read more >
ProduceAsync does not return when no kafka server is ...
Description Invoking await producer.ProduceAsync(topicName, null, val) in an async method does not return delivery report while kafka server ...
Read more >
.Net Publish to Kafka topic (efficiently) | by Jai Rathore ...
Recently, I had to integrate a couple of .Net 6 web applications with Kafka for both producing as well consuming messages.
Read more >
Building Reliable Kafka Producers and Consumers in .NET
After the producer exhausts the interval specified in the message.timeout.ms setting (default 300000), the producer will throw an exception ...
Read more >
Kafka Produce Not Throwing Exception when Unable to ...
A quick tip on dealing with failures and errors with Kafta.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found