0%

Spring-Integration-Channel

文章字数:377,阅读全文大约需要1分钟

channel最主要的作用就是作为一个传输Message的管道,Spring Integration中实现了各种各样的channel可以满足不同的需求。

一、顶级接口

  1. MessageChannel: 该接口中没有提供从channel中接收的方法,因为接收的方法被两个子接口表示。
1
2
boolean send(Message<?> message);
boolean sned(Message<?> message, long timeout);
  1. PollableChannel: 接收的子接口,具备轮询获取消息的能力。要求消息消费者或者框架周期性检测消息是否可达。
1
2
Message<?> receive();
Message<?> receive(long timeout);
  1. SubscribableChannel: 发送消息给订阅了MessageHanlder的订阅者
1
2
boolean subscribe(MessageHandler handler);
boolean unsubscribe(MessageHandler hanlder);

二、常用channel

  1. DirectChannel: 默认的Spring Integration默认的消息通道,它允许将消息发送给一个订阅者,然后阻碍发送直到消息被接收。同步发送。

  2. QueueChannel: 允许消息接收者轮询获得消息,用一个队列queue接收消息,队列的容量大小可配置。异步发送

  3. PublishSubscribeChannel: 允许广播消息给所有订阅者,不支持缓存即Quenue

  4. PriorityChannel: 可以按照优先级将数据存储到队列