2015-04-15 91 views
1

我有一個可翻轉通道並在其下游有一個過濾器。是否有可能使用過濾器來輪詢這樣的通道,或者我應該在兩者之間使用一些中間對手(我檢查了服務激活器,它至少可以接受可輪詢的通道,但也許有更好的選擇,例如某些網關):過濾可翻轉通道

<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

當然,發送後立即發送預發送 - 將消息轉儲到隊列中非常快。

過濾器在任務執行程序線程上調用,而不是發送線程。

您將在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] [email protected] received message: [Payload String content=xxx][Headers={id=9b5bf399-a137-daec-58bd-7cf7216d3dfc, timestamp=1429090193794}] 
+0

好吧,我明白你的意思,但過濾器不會被觸發的。當我添加一個服務激活器時,它會在收到消息後立即觸發。 – yuranos87

+0

必須有別的事情在進行; 「過濾器」與任何消費端點沒有區別。我只是進行了一個沒有問題的測試。將用我的結果編輯答案。 –