Kafka消费者并不总是接收到消息。

huangapple 未分类评论52阅读模式
英文:

Kafka Consumer doesn't always receive messages

问题

以下是您提供的内容的中文翻译:

所以我有一个 Kafka 消费者,但它并不总是从我的生产者接收消息,我不确定是否与 Zookeeper/Kafka 服务器随机死机或代码有关。

想知道这是否是一个常见问题?

生产者:

public SentenceProducer() {
    Properties properties = new Properties();
    properties.put("bootstrap.servers", "localhost:9092");
    properties.put("client.id", SentenceProducer.class.getName());
    producer = new KafkaProducer(properties, new StringSerializer(), new StringSerializer());
}

消费者:

public SentenceConsumer() {
    Properties properties = new Properties();
    properties.put("bootstrap.servers", "localhost:9092");
    properties.put("client.id", SentenceConsumer.class.getName());
    properties.put("group.id", "test");
    consumer = new KafkaConsumer(properties, new StringDeserializer(), new StringDeserializer());
    consumer.subscribe(Collections.singletonList("sentence"));
    detector = new LanguageDetector();
}
英文:

So I have this Kafka Consumer but it isn't always receiving messages from my producer and I'm not sure if it has to do with the Zookeeper/Kafka servers dying randomly or something to do with the code.

Was wondering if this is a common issue?

Producer:

    public SentenceProducer() {
        Properties properties = new Properties();
        properties.put("bootstrap.servers", "localhost:9092");
        properties.put("client.id", SentenceProducer.class.getName());
        producer = new KafkaProducer(properties, new StringSerializer(), new StringSerializer());
    }

Consumer:

    public SentenceConsumer() {
        Properties properties = new Properties();
        properties.put("bootstrap.servers", "localhost:9092");
        properties.put("client.id", SentenceConsumer.class.getName());
        properties.put("group.id", "test");
        consumer = new KafkaConsumer(properties, new StringDeserializer(), new StringDeserializer());
        consumer.subscribe(Collections.singletonList("sentence"));
        detector = new LanguageDetector();
    }

huangapple
  • 本文由 发表于 2020年4月5日 19:10:10
  • 转载请务必保留本文链接:https://java.coder-hub.com/61041618.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定