1、group:
創(chuàng)新互聯(lián)公司是一家集網(wǎng)站建設(shè),會昌企業(yè)網(wǎng)站建設(shè),會昌品牌網(wǎng)站建設(shè),網(wǎng)站定制,會昌網(wǎng)站建設(shè)報價,網(wǎng)絡(luò)營銷,網(wǎng)絡(luò)優(yōu)化,會昌網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競爭力。可充分滿足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時我們時刻保持專業(yè)、時尚、前沿,時刻以成就客戶成長自我,堅持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實用型網(wǎng)站。
組內(nèi)只有1個實例消費。如果不設(shè)置group,則stream會自動為每個實例創(chuàng)建匿名且獨立的group——于是每個實例都會消費
組內(nèi)單次只有1個實例消費,并且會輪詢負(fù)載均衡。通常,在將應(yīng)用程序綁定到給定目標(biāo)時,最好始終指定consumer group
2、destination binder:
與外部消息系統(tǒng)通信的組件,為構(gòu)造 Binding提供了 2 個方法,分別是 bindConsumer 和 bindProducer ,它們分別用于構(gòu)造生產(chǎn)者和消費者。Binder使Spring Cloud Stream應(yīng)用程序可以靈活地連接到中間件,目前spring為kafka、rabbitmq提供binder
3、destination binding:
Binding 是連接應(yīng)用程序跟消息中間件的橋梁,用于消息的消費和生產(chǎn),由binder創(chuàng)建
4、partition
一個或多個生產(chǎn)者將數(shù)據(jù)發(fā)送到多個消費者,并確保有共同特征標(biāo)識的數(shù)據(jù)由同一個消費者處理。默認(rèn)是對消息進(jìn)行hashCode,然后根據(jù)分區(qū)個數(shù)取余,所以對于相同的消息,總會落到同一個消費者上
注:嚴(yán)格來說partition不屬于概念,而是一種Stream提高伸縮性、吞吐量的一種方式
1、@Input,使用示例:
public interface MySink {
@Input("my-input")
SubscribableChannel input();
}
作用:
2、@Output,使用示例:
public interface MySource {
@Output("my-output")
MessageChannel output();
}
作用:
@Input
類似,只不過是用來生產(chǎn)消息3、@StreamListener,使用示例:
@StreamListener(value = Sink.INPUT, condition = "headers['type']=='dog'")
public void receive(String messageBody) {
log.info("Received: {}", messageBody);
}
作用:
4、@SendTo,使用示例:
// 接收INPUT這個channel的消息,并將返回值發(fā)送到OUTPUT這個channel
@StreamListener(Sink.INPUT)
@SendTo(Source.OUTPUT)
public String receive(String receiveMsg) {
return "handle...";
}
作用:
4、@InboundChannelAdapter,使用示例:
@Bean
@InboundChannelAdapter(value = Source.OUTPUT,
poller = @Poller(fixedDelay = "10", maxMessagesPerPoll = "1"))
public MessageSource<String> producer() {
return () -> new GenericMessage<>("Hello Spring Cloud Stream");
}
作用:
5、@ServiceActivator,使用示例:
@ServiceActivator(inputChannel = Sink.INPUT, outputChannel = Source.OUTPUT)
public String transform(String payload) {
return payload.toUpperCase();
}
作用:
6、@Transformer,使用示例:
@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public Object transform(String message) {
return message.toUpperCase();
}
作用:
@ServiceActivator
類似,標(biāo)注該注解的方法能夠轉(zhuǎn)換消息,消息頭,或消息有效內(nèi)容PollableMessageSource允許消費者可以控制消費速率。舉個例子簡單演示一下,首先定義一個接口:
public interface PolledProcessor {
@Input("pollable-input")
PollableMessageSource input();
}
使用示例:
@Autowired
private PolledProcessor polledProcessor;
@Scheduled(fixedDelay = 5_000)
public void poll() {
polledProcessor.input().poll(message -> {
byte[] bytes = (byte[]) message.getPayload();
String payload = new String(bytes);
System.out.println(payload);
});
}
參考:
https://spring.io/blog/2018/02/27/spring-cloud-stream-2-0-polled-consumers
本文題目:SpringCloudStream總結(jié)
標(biāo)題路徑:http://chinadenli.net/article26/gohhcg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、網(wǎng)站設(shè)計、建站公司、靜態(tài)網(wǎng)站、搜索引擎優(yōu)化、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)