我有这个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个线程。可用于消息处理。
答案 0 :(得分:0)
但你有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 {