[英]Spring Integration double poller
我有這個xml配置:
<int:annotation-config default-publisher-channel="messageChannel" />
<task:executor id="messageTaskExecutor" pool-size="1"
queue-capacity="1" rejection-policy="CALLER_RUNS" />
<int:transaction-synchronization-factory id="syncFactory">
<int:after-commit expression="@messageSessionStore.removeFromIdCache(headers.id.toString())" />
<int:after-rollback expression="@messageSessionStore.removeFromIdCache(headers.id.toString())" />
</int:transaction-synchronization-factory>
<bean id="messageQueryProvider"
class="org.springframework.integration.jdbc.store.channel.OracleChannelMessageStoreQueryProvider" />
<bean id="messageSessionStore"
class="org.springframework.integration.jdbc.store.JdbcChannelMessageStore">
<property name="dataSource" ref="dataSource" />
<property name="channelMessageStoreQueryProvider" ref="messageQueryProvider" />
<property name="tablePrefix" value="QUEUE_" />
<property name="usingIdCache" value="true" />
</bean>
<int:channel id="messageChannel">
<int:queue message-store="messageSessionStore" />
</int:channel>
<int:poller id="defaultPoller" fixed-delay="500" max-messages-per-poll="1" task-executor="messageTaskExecutor" default="true">
<int:transactional propagation="REQUIRED" synchronization-factory="syncFactory" isolation="READ_COMMITTED" transaction-manager="eosTransactionManager"/>
</int:poller>
這兩個bean,一個用於常規流,一個用於錯誤流:
@MessageEndpoint
public class NormalMessageHandler {
@Autowired
@Qualifier("errorChannel")
private MessageChannel errorMessageChannel;
@ServiceActivator(inputChannel = "messageChannel")
public void processMessage(final Message<?> message) {
}
}
@MessageEndpoint
public class ErrorMessageHandler {
@ServiceActivator(inputChannel = "errorChannel")
public void handleFailedMessage(Message<Exception> message) {
}
}
現在,我的隊列中(在數據庫中)有2條消息。 我希望它們可以互相處理,但是似乎以某種方式,此配置導致兩個單獨的線程觸發兩個消息的常規消息處理功能(當我在該函數中設置斷點時可以看到)。同時。 我想念什么嗎? 我希望任務執行程序的配置最多只能導致1個線程。 可用於消息處理。
但是,您那里有rejection-policy="CALLER_RUNS"
。 這意味着,如果您的任務執行者太忙,並且沒有空間通過其線程池來處理任務,則調用者現在對此負責。
考慮使用其他一些RejectedExecutionHandler
實現。 例如,Spring Integration提供了CallerBlocksPolicy
實現:
* A {@link RejectedExecutionHandler} that blocks the caller until
* the executor has room in its queue, or a timeout occurs (in which
* case a {@link RejectedExecutionException} is thrown.
*
* @author Gary Russell
* @since 3.0.3
*
*/
public class CallerBlocksPolicy implements RejectedExecutionHandler {
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.