Spring Cloud Stream 3.x 集成 RocketMQ
date
Aug 2, 2023
slug
Spring-Cloud-Stream-RocketMQ
status
Published
tags
MQ
summary
Spring Cloud Stream 3.x 集成 RocketMQ
type
Post
Language
配置
spring:
cloud:
stream:
rocketmq:
binder:
name-server: localhost:9876
function:
# 这里配置消费者函数名,多个函数以;隔开
definition: myTopic
bindings:
# 生产者,前缀必须以对应的 definition , out 代表生产者,0 代表索引
myTopic-out-0:
destination: my-topic
group: test
# 消费者,前缀必须以对应的 definition , in 代表消费者,0 代表索引
myTopic-in-0:
destination: my-topic手动发送消息
@Component
public class MQProducer {
@Resource
private StreamBridge streamBridge;
public void sendMsg() {
streamBridge.send("myTopic-out-0", "test");
}
}接收消息
@Component
public class MQConsumer {
public Consumer<String> myTopic() {
return message -> {
System.out.print(message )
}
}
}