springcloud stream 消息驅(qū)動

rabbitmq 與stream 結(jié)合入門應(yīng)用舉例:

一、消息生產(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>


producer pom文件

2、配置yml 文件:

如果用內(nèi)置接口,不會用到下面的 myoutput: 這個配置,可以刪除,

yml配置

3、定義消息發(fā)送接口, spring 內(nèi)置的一個消息發(fā)送接口已經(jīng)有一個:

public interface Source {? ??

String OUTPUT = "output";

@Output("output") ?
MessageChannel output();

}

4、發(fā)送消息


發(fā)送消息

二、消息消費者

1、引入和消息生產(chǎn)者一樣的依賴


消費者 pom

2/消費者中的對應(yīng)配置


消費者yml中對應(yīng)配置
消費者yml

3、定義消息接收接口, spring 內(nèi)置的一個消息接收接口已經(jīng)有一個:

public interface Sink {? ?

String INPUT = "input";

? ?@Input("input") ? ?
SubscribableChannel input();?

}

4、接收消息:

接收消息
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容