Java 弹簧靴卡夫卡不';t工作-消费者未接收消息

Java 弹簧靴卡夫卡不';t工作-消费者未接收消息,java,spring-boot,apache-kafka,Java,Spring Boot,Apache Kafka,我正在尝试运行一个简单的Spring Boot Kafka应用程序,但无法使其正常工作。我已经学习了各种教程,现在正在实施,但当我启动应用程序时,会发生以下情况: 我可以在控制台中写入,但消费者没有收到任何消息。 这是我的SpringApplication课程: @SpringBootApplication(scanBasePackages = "com.springmiddleware") @ComponentScan("com.springmiddleware") @EnableAutoC

我正在尝试运行一个简单的Spring Boot Kafka应用程序,但无法使其正常工作。我已经学习了各种教程,现在正在实施,但当我启动应用程序时,会发生以下情况:

我可以在控制台中写入,但消费者没有收到任何消息。
这是我的SpringApplication课程:

@SpringBootApplication(scanBasePackages = "com.springmiddleware")
@ComponentScan("com.springmiddleware")
@EnableAutoConfiguration
@EntityScan("com.springmiddleware")
public class SpringMiddlewareApplication implements CommandLineRunner{



    public static void main(String[] args) throws Exception {

        SpringApplication.run(SpringMiddlewareApplication.class, args);

    }

    @Autowired
    private Producer sender;

    @Override 
    public void run (String... strings) {
        sender.send("Hello world");
    }

}
application.yml:

spring:
  kafka:
    bootstrap-servers: localhost:8080

app:
  topic:
    foo: foo.t

logging:
  level:
    root: ERROR
    org.springframework.web: ERROR
    com.memorynotfound: DEBUG
消费者类、生产者类及其配置类与本教程中所述相同。
在我的server.properties文件中,我有:

zookeeper.connect=localhost:8080
在zookeeper.properties中:

clientPort=8080
application.yml中指定的端口相同。在启动应用程序之前,我运行

.\bin\windows\zookeeper-server-start.bat config\zookeeper.properties

更新

这是
ReceiverConfig
类:

@EnableKafka
@Configuration
public class ReceiverConfig {

    @Value("${spring.kafka.bootstrap-servers}")
    private String bootstrapServers;

    @Bean
    public Map<String, Object> consumerConfigs() {
        Map<String, Object> props = new HashMap<>();
        props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, bootstrapServers);
        props.put(ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
        props.put(ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, StringDeserializer.class);
        props.put(ConsumerConfig.GROUP_ID_CONFIG, "foo");
        props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest");

        return props;
    }

    @Bean
    public ConsumerFactory<String, String> consumerFactory() {
        return new DefaultKafkaConsumerFactory<>(consumerConfigs());
    }

    @Bean
    public KafkaListenerContainerFactory<ConcurrentMessageListenerContainer<String, String>> kafkaListenerContainerFactory() {
        ConcurrentKafkaListenerContainerFactory<String, String> factory = new ConcurrentKafkaListenerContainerFactory<>();
        factory.setConsumerFactory(consumerFactory());
        return factory;
    }

}
制片人级别:

@Service
public class Producer {

     @Autowired
     private KafkaTemplate<String, String> kafkaTemplate;

     @Value("${app.topic.foo}")
        private String topic;

     public void send(String message){
            kafkaTemplate.send(topic, message);
        }
}
@服务
公共级制作人{
@自动连线
私人卡夫卡模板卡夫卡模板;
@值(${app.topic.foo}”)
私有字符串主题;
公共无效发送(字符串消息){
发送(主题、消息);
}
}
更新2

[2019-04-01 17:23:52492]信息已建立会话0x10043595088000,客户端协商超时6000/0:0:0:0:0:0:1:60079(org.apache.zookeeper.server.ZooKeeperServer) [2019-04-01 17:23:52539]处理会话ID:0x10043595088000类型:create cxid:0x1 zxid:0xef txntype:-1请求路径:n/a错误路径:/consumers错误:keeperrorcode=NodeExists for/consumers(org.apache.zookeer.server.prerequestprocessor) [2019-04-01 17:23:52555]处理会话ID:0x10043595088000类型:创建cxid:0x2 zxid:0xf0 txntype:-1请求路径:n/a错误路径:/brokers/ids错误:keeperrorcode=NodeExists for/brokers/ids(org.apache.zookeer.server.prerequestprocessor) [2019-04-01 17:23:52555]处理会话ID:0x10043595088000类型:create cxid:0x3 zxid:0xf1 txntype:-1请求路径:n/a错误路径:/brokers/topics错误:keeperrorcode=NodeExists for/brokers/topics(org.apache.zookeer.server.prerequestprocessor) [2019-04-01 17:23:52555]处理会话ID:0x10043595088000类型:create cxid:0x4 zxid:0xf2 txntype:-1请求路径:n/a错误路径:/config/changes错误:keeperrorcode=NodeExists for/config/changes(org.apache.zookeer.server.prerequestprocessor) [2019-04-01 17:23:52570]处理会话ID:0x10043595088000类型:create cxid:0x5 zxid:0xf3 txntype:-1请求路径:n/a错误路径:/admin/delete_主题错误:keeperrorcode=NodeExists for/admin/delete_主题(org.apache.zookeer.server.prerequestprocessor) [2019-04-01 17:23:52570]处理会话ID:0x10043595088000类型:创建cxid:0x6 zxid:0xf4 txntype:-1请求路径:n/a错误路径:/brokers/seqid错误:keeperrorcode=NodeExists for/brokers/seqid(org.apache.zookeer.server.prerequestprocessor) [2019-04-01 17:23:52586]处理会话ID:0x10043595088000类型:create cxid:0x7 zxid:0xf5 txntype:-1请求路径:n/a错误路径:/isr\u change\u通知错误:keeperrorcode=NodeExists for/isr\u change\u通知(org.apache.zookeer.server.prerequestprocessor) [2019-04-01 17:23:52586]信息在处理会话时获得了用户级别的KeeperException id:0x10043595088000类型:创建cxid:0x8 zxid:0xf6 txntype:-1请求路径:n/a错误路径:/latest_producer_id_block错误:KeeperrorCode=NodeExists for/latest_producer_id_block(org.apache.zookeer.server.prerequestProcessor) [2019-04-01 17:23:52586]处理会话ID:0x10043595088000类型:create cxid:0x9 zxid:0xf7 txntype:-1请求路径:n/a错误路径:/log_dir_event_通知错误:keeperrorcode=NodeExists for/log_dir_event_通知(org.apache.zookeer.server.prerequestprocessor) [2019-04-01 17:23:52602]处理会话ID:0x10043595088000类型:create cxid:0xa zxid:0xf8 txntype:-1请求路径:n/a错误路径:/config/topics错误:keeperrorcode=NodeExists for/config/topics(org.apache.zookeer.server.prerequestprocessor) [2019-04-01 17:23:52602]处理会话ID:0x10043595088000类型:create cxid:0xb zxid:0xf9 txntype:-1请求路径:n/a错误路径:/config/clients错误:keeperrorcode=NodeExists for/config/clients(org.apache.zookeer.server.prerequestprocessor) [2019-04-01 17:23:52617]处理会话ID:0x10043595088000类型:create cxid:0xc zxid:0xfa txntype:-1请求路径:n/a错误路径:/config/users错误:keeperrorcode=NodeExists for/config/users(org.apache.zookeer.server.prerequestprocessor) [2019-04-01 17:23:52617]处理会话ID:0x10043595088000类型:create cxid:0xd zxid:0xfb txntype:-1请求路径:n/a错误路径:/config/brokers错误:keeperrorcode=NodeExists for/config/brokers(org.apache.zookeer.server.prerequestprocessor) [2019-04-01 17:23:53564]处理会话ID:0x10043595088000类型:multi-cxid:0x3a zxid:0xff txntype:-1请求路径:n/a中止剩余的多操作时,信息获取了用户级别的KeeperException。错误路径:/admin/preferred\u replica\u election错误:keeperrorcode=NoNode for/admin/preferred\u replica\u election(org.apache.zookeer.server.prerequestprocessor)


应用程序.yml中,您指定了zookeeper端口,而不是kafka代理端口

spring:
  kafka:
    bootstrap-servers: localhost:8080
在上面,您应该定义kafka代理的端口,即server.properties文件的
port=
的值

默认情况下,Spring boot应用程序在端口8080上运行,因此请不要将其用于Zookeeper端口,除非
@KafkaListener(topics = "${app.topic.foo}")
    public void listen(@Payload String message) {
        System.out.println("Received " + message);
    }
@Service
public class Producer {

     @Autowired
     private KafkaTemplate<String, String> kafkaTemplate;

     @Value("${app.topic.foo}")
        private String topic;

     public void send(String message){
            kafkaTemplate.send(topic, message);
        }
}
spring:
  kafka:
    bootstrap-servers: localhost:8080
spring:
  kafka:
    bootstrap-servers: localhost:9092