Spring Cloud Stream RabbitMQ 示例
时间: 2023-07-21 13:45:32 浏览: 66
好的,这里是一个简单的 Spring Cloud Stream RabbitMQ 示例:
首先,需要在 pom.xml 文件中添加以下依赖:
```
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-stream-binder-rabbit</artifactId>
</dependency>
```
接下来,创建一个发送消息的接口:
```
public interface MessageSender {
@Output("output_channel")
MessageChannel output();
}
```
然后创建一个接收消息的接口:
```
public interface MessageReceiver {
@Input("input_channel")
SubscribableChannel input();
}
```
在 application.yml 文件中配置 RabbitMQ:
```
spring:
cloud:
stream:
bindings:
output_channel:
destination: myExchange
content-type: application/json
input_channel:
destination: myExchange
content-type: application/json
rabbit:
bindings:
output_channel:
producer:
exchangeType: topic
input_channel:
consumer:
exchangeType: topic
queueNameGroupOnly: true
```
最后,使用 MessageSender 接口发送消息,使用 MessageReceiver 接口接收消息即可。
这就是一个简单的 Spring Cloud Stream RabbitMQ 示例。