SpringCloud Spring Integration支持

2023-11-25 09:15 更新

Spring Cloud Stream建立在Enterprise Integration Patterns定義的概念和模式的基礎之上,并依靠其內(nèi)部實現(xiàn)依賴于Spring項目組合 Spring Integration 框架中已經(jīng)建立且流行的Enterprise Integration Patterns實現(xiàn) 。

因此,它支持Spring Integration已經(jīng)建立的基礎,語義和配置選項是很自然的。

例如,您可以將Source的輸出通道附加到MessageSource并使用熟悉的@InboundChannelAdapter注釋,如下所示:

@EnableBinding(Source.class)
public class TimerSource {

  @Bean
  @InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "10", maxMessagesPerPoll = "1"))
  public MessageSource<String> timerMessageSource() {
    return () -> new GenericMessage<>("Hello Spring Cloud Stream");
  }
}

同樣,可以在提供處理器綁定合同的消息處理程序方法的實現(xiàn)時使用@Transformer或@ServiceActivator ,如以下示例所示:

@EnableBinding(Processor.class)
public class TransformProcessor {
  @Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
  public Object transform(String message) {
    return message.toUpperCase();
  }
}
盡管這可能會略過一些,但重要的是要了解,當您使用@StreamListener注釋從同一綁定進行消費時,將使用pub-sub模型。用@StreamListener注釋的每種方法都收到其自己的消息副本,并且每種方法都有其自己的使用者組。但是,如果通過使用Spring Integration批注之一(例如@Aggregator,@Transformer@ServiceActivator)從同一綁定中消費,則這些消費在競爭模型中。沒有為每個訂閱創(chuàng)建單獨的消費者組。


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號