I am trying to implement kafka producer and consumer with dot net running through docker but it is not producing messages to topic and giving this error....my broker is running and even I am able to implement the same in cmd but not through dot net console app
%3|1684755847.168|FAIL|rdkafka#producer-1| [thrd:kafka:9092/1001]: kafka:9092/1001: Connect to ipv4#172.104.101.12:9092 failed: Unknown error (after 23388ms in state CONNECT)
%3|1684755847.170|ERROR|rdkafka#producer-1| [thrd:app]: rdkafka#producer-1: kafka:9092/1001: Connect to ipv4#172.104.101.12:9092 failed: Unknown error (after 23388ms in state CONNECT)
using Confluent.Kafka;
using Newtonsoft.Json;
namespace KafkaProducer
{
class Program
{
//private const string BootstrapServers = "localhost:9092";
private const string Topic = "foo-too";
static async Task Main(string[] args)
{
var config = new ProducerConfig
{
BootstrapServers = "localhost:9092"
};
using (var producer = new ProducerBuilder<Null, string>(config).Build())
{
while (true)
{
Console.WriteLine("Enter a message (or 'exit' to quit):");
var message = Console.ReadLine();
if (message == "exit")
break;
var messageValue = JsonConvert.SerializeObject(message);
var result = await producer.ProduceAsync(Topic, new Message<Null, string> { Value = messageValue });
Console.WriteLine($"Message delivered to {result.TopicPartitionOffset}");
}
}
}
}
}
here is my docker compose
---
version: '3.4'
services:
zookeeper:
image: confluentinc/cp-zookeeper:latest
hostname: zookeeper
container_name: zookeeper
ports:
- "2181:2181"
environment:
ZOOKEEPER_CLIENT_PORT: 2181
ZOOKEEPER_TICK_TIME: 2000
broker:
image: confluentinc/cp-server
hostname: broker
container_name: broker
depends_on:
- zookeeper
ports:
- "9092:9092"
environment:
KAFKA_BROKER_ID: 1
KAFKA_ZOOKEEPER_CONNECT: 'zookeeper:2181'
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://broker:29092,PLAINTEXT_HOST://192.168.1.1:9092
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_CONFLUENT_LICENSE_TOPIC_REPLICATION_FACTOR: 1
CONFLUENT_SUPPORT_CUSTOMER_ID: 'anonymous'