如需使用最新稳定版本,请使用 Spring Integration 7.0.4spring-doc.cadn.net.cn

The MessageChannel 接口

Spring Integration 的顶级 MessageChannel 接口定义如下:spring-doc.cadn.net.cn

public interface MessageChannel {

    boolean send(Message message);

    boolean send(Message message, long timeout);
}

当发送消息时,如果消息发送成功,则返回值为true。 如果发送调用超时或被中断,则返回值为falsespring-doc.cadn.net.cn

PollableChannel

由于消息通道可能会或可能不会缓冲消息(如在Spring Integration概述中所述),因此定义了两个子接口来区分有缓存的可轮询通道和无缓存的订阅式通道。 以下列表显示了PollableChannel接口的定义:spring-doc.cadn.net.cn

public interface PollableChannel extends MessageChannel {

    Message<?> receive();

    Message<?> receive(long timeout);

}

如同发送消息的方法一样,在接收消息时,如果发生超时或中断,返回值为null。spring-doc.cadn.net.cn

SubscribableChannel

The SubscribableChannel 基础接口由直接将消息发送到其订阅的 MessageHandler 实例的通道实现。 因此,它们不提供用于轮询的接收方法。 相反,它们定义了用于管理这些订阅者的方法。 以下清单显示了 SubscribableChannel 接口的定义:spring-doc.cadn.net.cn

public interface SubscribableChannel extends MessageChannel {

    boolean subscribe(MessageHandler handler);

    boolean unsubscribe(MessageHandler handler);

}