[英]How to configure outbound channel adapter with synchronization factory in spring boot
spring 引導中的以下出站通道適配器配置等效於什么? 假設定義了messageChannel
、 taskExecutor
和synchronizationFactory
。
<int:outbound-channel-adapter id="outboundChannelAdapter" channel="messageChannel" ref="handler" method="handle">
<int:poller task-executor="taskExecutor" fixed-delay="500" receive-timeout="500" max-messages-per-poll="10">
<int:transactional synchronization-factory="synchronizationFactory" isolation="READ_COMMITTED"/>
</int:poller>
</int:outbound-channel-adapter>
帶有@Poller
注釋的@ServiceActivator
似乎沒有事務同步工廠的選項。 PollerMetadata
有一個選項,但我不確定如何將該實例連接到@ServiceActivator
。
在這種情況下需要同步工廠,因為它是一個基於 DB 的通道,有多個線程從中讀取。
像這樣的東西:
@ServiceActivator(inputChannel = "messageChannel", poller = @Poller("myPollerMetadata"))
public void handle(Message<?> message) { // Or what is your service method signature
...
}
@Bean
PollerMetadata myPollerMetadata(Executor taskExecutor, TransactionSynchronizationFactory synchronizationFactory) {
PollerMetadata poller = new PollerMetadata();
poller.setTransactionSynchronizationFactory(synchronizationFactory);
poller.setMaxMessagesPerPoll(10);
poller.setReceiveTimeout(500);
poller.setTaskExecutor(taskExecutor);
poller.setTrigger(new PeriodicTrigger(500));
return poller;
}
You may also consider to start learning Spring Integration Java DSL: https://docs.spring.io/spring-integration/reference/html/dsl.html#java-dsl . 相同的配置看起來像這樣:
@Bean
IntegrationFlow myHandlerFlow(Executor taskExecutor, TransactionSynchronizationFactory synchronizationFactory) {
return IntegrationFlows.from("messageChannel")
.handle(handler, "handle",
c -> c.poller(p -> p
.fixedDelay(500)
.transactionSynchronizationFactory(synchronizationFactory)
.taskExecutor(taskExecutor)
.receiveTimeout(500)
.maxMessagesPerPoll(10)))
.get();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.