The MessageChannel Interface
Spring Integration 的顶级 MessageChannel 接口定义如下:
Spring Integration’s top-level MessageChannel
interface is defined as follows:
public interface MessageChannel {
boolean send(Message message);
boolean send(Message message, long timeout);
}
在发送消息时,如果消息已成功发送,则返回值为 true。如果 send 调用超时或被中断,则返回 false。
When sending a message, the return value is true
if the message is sent successfully.
If the send call times out or is interrupted, it returns false
.
PollableChannel
因为消息通道可能缓冲或不缓冲消息(如 Spring Integration Overview 所述),所以两个子接口定义了缓冲(可轮询)和非缓冲(可订阅)通道行为。以下清单显示了 PollableChannel
接口的定义:
Since message channels may or may not buffer messages (as discussed in the Spring Integration Overview), two sub-interfaces define the buffering (pollable) and non-buffering (subscribable) channel behavior.
The following listing shows the definition of the PollableChannel
interface:
public interface PollableChannel extends MessageChannel {
Message<?> receive();
Message<?> receive(long timeout);
}
与 send 方法一样,在接收消息时,对于超时或中断,返回值为 null。
As with the send methods, when receiving a message, the return value is null in the case of a timeout or interrupt.
SubscribableChannel
可订阅通道基础接口由直接将其消息发送到其订阅的 MessageHandler 实例的通道实现。因此,它们不提供用于轮询的接收方法。相反,它们定义了用于管理这些订阅者的方法。以下清单显示了 SubscribableChannel 接口的定义:
The SubscribableChannel
base interface is implemented by channels that send messages directly to their subscribed MessageHandler
instances.
Therefore, they do not provide receive methods for polling.
Instead, they define methods for managing those subscribers.
The following listing shows the definition of the SubscribableChannel
interface:
public interface SubscribableChannel extends MessageChannel {
boolean subscribe(MessageHandler handler);
boolean unsubscribe(MessageHandler handler);
}