1

I have 2 docker containers running:

docker container ls
CONTAINER ID   IMAGE                         COMMAND                  CREATED       STATUS       PORTS                    NAMES
b92bf8cba740   ubuntu/kafka:3.1-22.04_beta   "entrypoint.sh /etc/…"   9 hours ago   Up 9 hours   0.0.0.0:9092->9092/tcp   kafka-container
d5b3e13ea717   ubuntu/zookeeper:edge         "/opt/kafka/bin/zook…"   9 hours ago   Up 9 hours   0.0.0.0:2181->2181/tcp   vigilant_sammet

https://hub.docker.com/r/ubuntu/kafka

and I'm trying to create "hello world" producer app with Go's library for kafka "sarama"

package main

import (
    "log"

    "github.com/IBM/sarama"
)

const (
    topic = "quickstart"
)

func main() {
    brokers := []string{"localhost:9092"}
    cfg := sarama.NewConfig()
    cfg.Producer.Return.Successes = true

    producer, err := sarama.NewSyncProducer(brokers, cfg)
    if err != nil {
        log.Fatal(err)
    }
    msg := sarama.ProducerMessage{
        Topic:     topic,
        Partition: -1,
        Value:     sarama.StringEncoder("Hello world"),
    }
    partition, offset, err := producer.SendMessage(&msg)
    if err != nil {
        log.Print("Failed to sent message", err)
    }
    log.Printf("Sent message to partiotion %d with offset %d", partition, offset)
}

with following result:

Failed to sent messagedial tcp: lookup b92bf8cba740: no such host
Sent message to partiotion -1 with offset -1

What am I doing wrong here?

Tom
  • 355
  • 4
  • 13

0 Answers0