Spring Batch中的kafka生产者,多线程编写者将重复消息发送到主题

问题描述

我正在使用Writer的Spring Batch(如果条件失败,也有重试逻辑,如果再次失败,请尝试再次执行),并且如果条件在Writer中得到满足,我正在尝试向主题发送Kafka消息。我正在使用在配置中实例化了Bean的Kafka模板。

    @Bean
    public Producer<Long,String> producerConfigs() {
        Properties props =  new Properties();
        //bootstrap servers and protocol configs here        
        props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG,LongSerializer.class);
        props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG,StringSerializer.class);
        return new KafkaProducer<>(props);
    }

在编写器部分,我在executorService.submit(...)中使用了线程计数为50,我正在使用以下代码将消息发送到主题

    public void send(String message){
        LOG.info("sending message='{}' to topic='{}'",message,topic);
        kafkaTemplate.send(topic,message).get();
    }

我的问题是我正在获取有关该主题的重复日志和重复的Kafka消息。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...