小编Swa*_*pta的帖子

使用Apache Kafka的Spring Boot:无法读取消息

我目前正在使用Kafka侦听器设置Spring Boot应用程序。我试图只编码消费者。对于生产者,我现在暂时从Kafka控制台手动发送消息。我按照示例进行操作:http : //www.source4code.info/2016/09/spring-kafka-consumer-producer-example.html

我尝试将其作为Spring Boot应用程序运行,但看不到收到的任何消息。在我的本地Kafka主题中已经有一些消息。

C:\software\kafka_2.11-0.10.1.0\kafka_2.11-0.10.1.0\kafka_2.11-0.10.1.0\bin\wind
ows>kafka-console-producer.bat --broker-list localhost:9092 --topic test
this is a message
testing again
Run Code Online (Sandbox Code Playgroud)

我的Spring Boot应用程序是:

@EnableDiscoveryClient
@SpringBootApplication
public class KafkaApplication {

    /**
     * Run the application using Spring Boot and an embedded servlet engine.
     * 
     * @param args
     *            Program arguments - ignored.
     */
    public static void main(String[] args) {
        // Tell server to look for registration.properties or registration.yml
        System.setProperty("spring.config.name", "kafka-server");

        SpringApplication.run(KafkaApplication.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

Kafka的配置是:

package kafka;

import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.common.serialization.IntegerDeserializer;
import org.apache.kafka.common.serialization.StringDeserializer; …
Run Code Online (Sandbox Code Playgroud)

apache-kafka spring-boot

4
推荐指数
1
解决办法
8618
查看次数

标签 统计

apache-kafka ×1

spring-boot ×1