<!-- kafka -->
<dependency>
<groupId>org.springframework.kafka</groupId>
<artifactId>spring-kafka</artifactId>
<version>2.8.2</version>
</dependency>
如果启动报错:Error creating bean with name ‘kafkaTemplate‘ defined in class path resource 那就是springboot版本和kafka不兼容 去找对应版本兼容
2.配置文件代码如下(示例):
spring.kafka.bootstrap-servers=xxx:9092,xxx:9092,xxx:9092//接入点 kafka的环境ip
spring.kafka.producer.key-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.producer.value-serializer=org.apache.kafka.common.serialization.StringSerializer
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer
spring.kafka.consumer.group-id=model //消费者名字
示例代码
@Component
public class KafkaTest {
@KafkaListener(topics = "model") //topic的名称
public void kafkaConsume(String content){
System.out.println("kafka消息消费:"+content);
}
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)