我有一个用 @ServiceActivator("CH1") 注释的方法,其中“CH1”定义是:
@Bean(name = "CH1")
MessageChannel ch1() {
return new PublishSubscribeChannel
}
以及其他 PollableChannels 通过
发布到此 channel@BidgeTo(value = "CH1", poller = @Poller("myPoller"))
大多数时候事情似乎都进展顺利;但是,消息处理程序似乎随机取消订阅“CH1”,我在日志中看到:
[DEBUG] (pool-2-thread-1) org.springframework.integration.dispatcher.BroadcastingDispatcher: No subscribers, default behavior is ignore
现在我知道我可以更改 minSubscribers 但我不明白为什么事情似乎随机取消订阅?发生此错误后,它将返回正常处理一些消息。消息处理程序是否在处理消息时取消订阅或者正在使用的执行器已满?我在日志中没有看到与此相关的错误,也没有在日志中取消订阅或将订阅者计数更新为“CH1”。
最佳答案
这没有道理。请分享一些测试用例,以便从框架的角度进行重现。
有关此事的源代码如下所示:
if (dispatched == 0 && this.minSubscribers == 0 && logger.isDebugEnabled()) {
if (sequenceSize > 0) {
logger.debug("No subscribers received message, default behavior is ignore");
}
else {
logger.debug("No subscribers, default behavior is ignore");
}
}
只有在以下情况下我们才能转到sequence == 0
:
Collection<MessageHandler> handlers = this.getHandlers();
if (this.requireSubscribers && handlers.size() == 0) {
throw new MessageDispatchingException(message, "Dispatcher has no subscribers");
}
int sequenceSize = handlers.size();
只有您的订阅者以某种方式取消订阅的线索......
我发现您的 CH1
有一个 DEBUG,因此当您看到该错误时,您是否介意分享整个 org.springframework.integration
的 DEBUG 日志。
编辑
另请注意,每当添加/删除订阅者时(例如,当启动/停止消费端点时),您都会看到此日志消息...
if (logger.isInfoEnabled()) {
logger.info("Channel '" + this.getFullChannelName() + "' has " + counter + " subscriber(s).");
}
(至少使用 INFO 日志记录进行记录时)。
关于java - ServiceActivator 'randomly' 取消订阅 PublishSubscribeChannel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35808154/