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

时间:2016-09-19 20:54:24

标签: spring spring-integration bridge

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

<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()总是返回0。

我做错了吗?

2 个答案:

答案 0 :(得分:0)

您错过了与我们分享测试用例。我们没有完整的图片。看起来你在那里有竞争条件。在您开始声明checkMyChannel之前,有人会从getqueuesize()轮询您的所有邮件。

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

答案 1 :(得分:0)

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

How to test Spring Integration 这个有帮助,因为我的情况有一个竞争条件。 “拥有多个订阅者的常规频道将循环播放......”

相关问题