spring 集成桥直接通道到队列通道

spring integration bridge direct channel to queue Channel

在单元测试时,我尝试将 Spring 集成默认通道桥接到排队通道,因为我想检查流入该通道的消息量的正确性。

<int:filter input-channel="prevChannel" output-channel="myChannel">
<int:bridge input-channel="myChannel" output-channel="aggregateChannel">
// the reason I have above bridge is I want to check the amount of message after filter.
// I cannot check prevChannel since it is before filtering, and I cannot check aggregateChannel 
// because it has other processing branch

// in test xml I import above normal workflow xml and added below configuration to 
// redirect message from myChannel to checkMyChannel to checking.


<int:bridge input-channel="myChannel"
            output-channel="checkMyChannel"/>

<int:channel id="checkMyChannel">    
    <int:queue/> 
</int:channel>

我在单元测试中自动连接了 checkMyChannel 但是 checkMyChannel.getqueuesize() 总是 return 0.

我做错了什么吗?

您错过了与我们分享测试用例。我们没有完整的图片。看起来你在那里有竞争条件。在您开始断言 getqueuesize().

之前,有人会从 checkMyChannel 轮询您的所有消息

在我们的测试中,我们不会对这种情况使用 <poller>。我们手动使用 PollableChannel.receive(timeout)

解决了这个问题,我必须将 myChannel 声明为发布-订阅-频道

How to test Spring Integration 这有帮助,因为我的情况是因为存在竞争条件。 "A regular channel with multiple subscribers will round-robin ..."