rabbitmq 與stream 結(jié)合入門應用舉例:
一、消息生產(chǎn)者:
1蹲诀、引入依賴:
<dependencies>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.springframework.cloud</groupId>
? ? ? ? ? ? <artifactId>spring-cloud-stream</artifactId>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.springframework.cloud</groupId>
? ? ? ? ? ? <artifactId>spring-cloud-starter-stream-rabbit</artifactId>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.springframework.cloud</groupId>
? ? ? ? ? ? <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
? ? ? ? </dependency>
? ? </dependencies>
2斑粱、配置yml 文件:
如果用內(nèi)置接口,不會用到下面的 myoutput: 這個配置脯爪,可以刪除则北,
3、定義消息發(fā)送接口痕慢, spring 內(nèi)置的一個消息發(fā)送接口已經(jīng)有一個:
public interface Source {? ??
String OUTPUT = "output";
@Output("output") ?
MessageChannel output();
}
4尚揣、發(fā)送消息
二、消息消費者
1掖举、引入和消息生產(chǎn)者一樣的依賴
2/消費者中的對應配置
3快骗、定義消息接收接口, spring 內(nèi)置的一個消息接收接口已經(jīng)有一個:
public interface Sink {? ?
String INPUT = "input";
? ?@Input("input") ? ?
SubscribableChannel input();?
}
4塔次、接收消息: