过滤可轮询频道

时间:2015-04-15 07:11:10

标签: java spring-integration

我有一个可轮询的通道和一个位于其下游的过滤器。是否可以使用过滤器轮询此类频道,或者我是否应该在其间使用一些中间组件(我检查了服务激活器。它至少可以接受可轮询频道,但也许有更好的选择,如某些网关):< / p>

    <task:executor id="task-executor" pool-size="10" queue-capacity="100"/>

    <int:channel id="inputChannel">
        <int:queue capacity="100" />
    </int:channel>

    <!--The filter is never triggered. The flow goes from input-channel preSend fight to its postSend-->
    <int:filter id="mailFilter" input-channel="inputChannel"
                output-channel="outputChannel" expression="@mailFilter.acceptMail(payload)"
                auto-startup="true" discard-channel="error-handler">
        <int:poller task-executor='task-executor' fixed-delay='500'>
        </int:poller>
</int:filter>

1 个答案:

答案 0 :(得分:1)

当然,发送后发送是在预发送之后 - 将消息转储到队列中的速度非常快。

在任务执行程序线程而不是发送线程上调用过滤器。

您将在DEBUG级别看到preReceive日志(在TRACE级别)和postReceive

修改

我刚刚运行了一个没有问题的测试...

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

<int:filter input-channel="foo" output-channel="toRabbit" expression="true">
    <int:poller fixed-delay="2000" />
</int:filter>


10:29:53.792 TRACE [task-scheduler-1][org.springframework.integration.channel.QueueChannel] preReceive on channel 'foo'
10:29:53.795 DEBUG [task-scheduler-4][org.springframework.integration.endpoint.SourcePollingChannelAdapter] Poll resulted in Message: [Payload String content=xxx][Headers={id=9b5bf399-a137-daec-58bd-7cf7216d3dfc, timestamp=1429090193794}]
10:29:53.795 DEBUG [task-scheduler-4][org.springframework.integration.channel.QueueChannel] preSend on channel 'foo', message: [Payload String content=xxx][Headers={id=9b5bf399-a137-daec-58bd-7cf7216d3dfc, timestamp=1429090193794}]
10:29:53.795 DEBUG [task-scheduler-4][org.springframework.integration.channel.QueueChannel] postSend (sent=true) on channel 'foo', message: [Payload String content=xxx][Headers={id=9b5bf399-a137-daec-58bd-7cf7216d3dfc, timestamp=1429090193794}]
10:29:53.795 DEBUG [task-scheduler-1][org.springframework.integration.channel.QueueChannel] postReceive on channel 'foo', message: [Payload String content=xxx][Headers={id=9b5bf399-a137-daec-58bd-7cf7216d3dfc, timestamp=1429090193794}]
10:29:53.795 DEBUG [task-scheduler-1][org.springframework.integration.endpoint.PollingConsumer] Poll resulted in Message: [Payload String content=xxx][Headers={id=9b5bf399-a137-daec-58bd-7cf7216d3dfc, timestamp=1429090193794}]
10:29:53.796 DEBUG [task-scheduler-1][org.springframework.integration.filter.MessageFilter] org.springframework.integration.filter.MessageFilter@2ecd0256 received message: [Payload String content=xxx][Headers={id=9b5bf399-a137-daec-58bd-7cf7216d3dfc, timestamp=1429090193794}]