doukong1391 2018-03-18 02:54
浏览 61

卡夫卡制片人恐慌

I'm working on building kafka producer based on golang right now. I cannot sent any message from my producer. The panic shown as follow:

producer close, err: kafka: client has run out of available brokers to talk to(Is your cluster reachable?)

I test the kafka-console-consumer and kafka-console-producer, they are all work well on terminal. So, is there anything I missed? Here's the code:

package main
import (
    "github.com/Shopify/sarama"
    "log"
    "os"
    "strings"
)

var (
    logger = log.New(os.Stderr, "[srama]", log.LstdFlags)
)

func main() {
    sarama.Logger = logger

    config := sarama.NewConfig()
    config.Producer.Return.Successes = true
    config.Producer.RequiredAcks = sarama.WaitForAll
    config.Producer.Partitioner = sarama.NewRandomPartitioner

    msg := &sarama.ProducerMessage{}
    msg.Topic = "hello"
    msg.Partition = int32(-1)
    msg.Key = sarama.StringEncoder("key")
    msg.Value = sarama.ByteEncoder("hello, world!")

    producer, err := sarama.NewSyncProducer(strings.Split("localhost:9092", ","), config)//default port
    if err != nil {
        logger.Println("Failed to produce message: %s", err)
        os.Exit(500)
    }
    defer producer.Close()

    partition, offset, err := producer.SendMessage(msg)
    if err != nil {
        logger.Println("Failed to produce message: ", err)
    }
    logger.Printf("partition=%d, offset=%d
", partition, offset)
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 虚幻5 UE美术毛发渲染
    • ¥15 CVRP 图论 物流运输优化
    • ¥15 Tableau online 嵌入ppt失败
    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测