关于警告 "Dispatcher has no subscribers"

About warn "Dispatcher has no subscribers"

我想使用PublishSubscribeAmqpChannel通过rabbitmq向其他系统发送消息,而我的系统不需要使用这个消息。当我这样做时,我总是收到警告“Dispatcher 没有 amqp-channel 'xxxxxxxxxxxxxxxxxxxxxxxx”的订阅者。我想知道正常吗?我想知道如何在不更改日志级别的情况下使它不显示在我的日志中。

PublishSubscribeAmqpChannel的逻辑是这样的:

protected AbstractDispatcher createDispatcher() {
    BroadcastingDispatcher broadcastingDispatcher = new BroadcastingDispatcher(true);

其中 true 表示:

public BroadcastingDispatcher(boolean requireSubscribers) {

然后在逻辑上更进一步:

public boolean dispatch(Message<?> message) {
    int dispatched = 0;
    int sequenceNumber = 1;
    Collection<MessageHandler> handlers = this.getHandlers();
    if (this.requireSubscribers && handlers.size() == 0) {
        throw new MessageDispatchingException(message, "Dispatcher has no subscribers");
    }

所以,这意味着这种消息渠道不能没有消费者发送的消息的任何订阅者。这感觉很可疑,因为当集群中的一个节点没有任何消费者时,我肯定有一个逻辑,同时所有节点都可以发送到这个通道。我们可以重新考虑这个逻辑。欢迎在 Github 上提出问题,以便我们进行一些团队讨论。

尽管如此,这个逻辑看起来对您的要求来说不是问题。您所说的 send-n-forget 不是使用 MessageChannel 抽象的正确方法。您使用常规 AmqpOutboundEndpoint 作为出站通道适配器有什么问题?

有关详细信息,请参阅文档:https://docs.spring.io/spring-integration/docs/current/reference/html/amqp.html#amqp-outbound-channel-adapter