过滤可轮询通道

filtering pollable channel

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

    <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>

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

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

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

编辑:

我刚运行测试没问题...

<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}]