文章字数:377,阅读全文大约需要1分钟
channel
最主要的作用就是作为一个传输Message
的管道,Spring Integration
中实现了各种各样的channel
可以满足不同的需求。
一、顶级接口
MessageChannel
: 该接口中没有提供从channel
中接收的方法,因为接收的方法被两个子接口表示。
1 2
| boolean send(Message<?> message); boolean sned(Message<?> message, long timeout);
|
PollableChannel
: 接收的子接口,具备轮询获取消息的能力。要求消息消费者或者框架周期性检测消息是否可达。
1 2
| Message<?> receive(); Message<?> receive(long timeout);
|
SubscribableChannel
: 发送消息给订阅了MessageHanlder
的订阅者
1 2
| boolean subscribe(MessageHandler handler); boolean unsubscribe(MessageHandler hanlder);
|
二、常用channel
DirectChannel
: 默认的Spring Integration
默认的消息通道,它允许将消息发送给一个订阅者,然后阻碍发送直到消息被接收。同步发送。
QueueChannel
: 允许消息接收者轮询获得消息,用一个队列queue
接收消息,队列的容量大小可配置。异步发送
PublishSubscribeChannel
: 允许广播消息给所有订阅者,不支持缓存即Quenue
PriorityChannel
: 可以按照优先级将数据存储到队列