Quarkus使用Kafka发送及接收消息
如果是gradle项目,在build.gradle中添加依赖
implementation "io.quarkus:quarkus-smallrye-reactive-messaging-kafka"
如果是maven项目,在pom.xml中添加依赖
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-reactive-messaging-kafka</artifactId>
</dependency>
在application.properties文件中添加配置属性
# kafka地址
kafka.bootstrap.servers=localhost:9092
# 设置连接器名称,my-outgoing-channel为生产者自定义的channel名称,my-incoming-channel为消费者自定义的channel名称
mp.messaging.outgoing.my-outgoing-channel.connector=smallrye-kafka
mp.messaging.incoming.my-incoming-channel.connector=smallrye-kafka
# 设置主题,将channel连接到指定的主题,此时如果主题未创建,则创建并连接
mp.messaging.outgoing.my-outgoing-channel.topic=my-test-topic
mp.messaging.incoming.my-incoming-channel.topic=my-test-topic
# 设置主题的分区数量