# cloud-stream-demo **Repository Path**: youxiu326/cloud-stream-demo ## Basic Information - **Project Name**: cloud-stream-demo - **Description**: cloud stream rabbit整合学习 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-03-23 - **Last Updated**: 2022-03-23 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #### 简单的入门 ```java 消息生产者 spring: application: name: stream-producer # 应用名称 rabbitmq: host: 127.0.0.1 port: 5672 username: guest password: guest virtual-host: / cloud: stream: bindings: # 消息发送通道 msg-output: destination: stream.msg # 绑定指定的交换机 => stream.msg @Component public interface OutputInterface { String MSG_OUTPUT ="msg-output"; // 配置发送消息的channel @Output(MSG_OUTPUT) MessageChannel sendMsg(); } // 发送消息工具类 @Component @EnableBinding(OutputInterface.class) public class MsgProducer { @Autowired private OutputInterface outputInterface; /** * 发送消息 * @param message */ public void send(String message){ outputInterface.sendMsg().send(MessageBuilder.withPayload(message).build()); } } ``` ```java 消息消费者 spring: application: name: stream-consumer rabbitmq: host: 127.0.0.1 port: 5672 username: guest password: guest virtual-host: / cloud: stream: bindings: # 消息接收通道 msg-input: destination: stream.msg # 绑定的交换机名称 @Component public interface InputInterface { String MSG_INPUT ="msg-input"; // 配置接收消息的channel @Input(MSG_INPUT) SubscribableChannel receiveMsg(); } @Component @EnableBinding(InputInterface.class) public class MsgConsumer { /** * 监听消息 * @param message */ @StreamListener(InputInterface.MSG_INPUT) public void receive(String message){ System.out.println("message = "+ message); } } ```