简体   繁体   English

如何在 spring 引导中配置带同步工厂的出站通道适配器

[英]How to configure outbound channel adapter with synchronization factory in spring boot

What would be the equivalent of the following outbound channel adapter configuration in spring boot? spring 引导中的以下出站通道适配器配置等效于什么? Assuming the messageChannel , taskExecutor , and synchronizationFactory are defined.假设定义了messageChanneltaskExecutorsynchronizationFactory

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

The @ServiceActivator with the @Poller annotation doesn't seem to have an option for transaction synchronization factory.带有@Poller注释的@ServiceActivator似乎没有事务同步工厂的选项。 The PollerMetadata has an option for it but I'm not sure how to connect that instance to the @ServiceActivator . PollerMetadata有一个选项,但我不确定如何将该实例连接到@ServiceActivator

The synchronization factory is needed in this case because it's a DB-based channel with multiple threads reading from it.在这种情况下需要同步工厂,因为它是一个基于 DB 的通道,有多个线程从中读取。

Something like this:像这样的东西:

@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 . You may also consider to start learning Spring Integration Java DSL: https://docs.spring.io/spring-integration/reference/html/dsl.html#java-dsl . The same config would look like this:相同的配置看起来像这样:

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

相关问题 没有弹簧集成的出站通道适配器 - Outbound Channel Adapter without spring integration 如何使用Spring集成或出站通道适配器将单个文件发送到多个主机 - How to send a single file to multiple host using spring integration or using outbound channel adapter 春季从MQTT出站通道适配器获取事件 - Spring getting events from the MQTT outbound channel adapter Spring-Integration-Kafka出站通道适配器发送消息 - Spring-Integration-Kafka outbound-channel-adapter Send message Spring Integration Java DSL中的JPA出站通道适配器配置 - JPA outbound channel adapter config in Spring Integration Java DSL Spring Integration outbound-channel-adapter destination-expression MQMDMessageContext - Spring Integration outbound-channel-adapter destination-expression MQMDMessageContext 如何声明两个出站通道适配器以发布不同的消息 - How to declare two outbound-channel-adapter for publishing different message 使用Mongo出站通道适配器时如何获取UpsertResult? - How to get UpsertResult when using Mongo Outbound channel adapter? 通道到多个出站通道适配器 - Channel to multiple outbound-channel-adapter 与DSL的Spring集成:间隔10分钟后,文件出站通道适配器可以创建文件吗? - Spring Integration with DSL: Can File Outbound Channel Adapter create file after say 10 mins of interval
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM