【问题标题】:Implementing Polling in Middle of spring Integration flow DSL在 Spring 集成流 DSL 中间实现轮询
【发布时间】:2020-08-10 09:35:49
【问题描述】:

我正在编写一个 spring 集成 DSL 流程。 如下图所示。

正如您在流程中看到的,我需要从数据库中读取 1 百万个实体。我想避免一次性阅读这些内容。

我想实现轮询,它会以固定的间隔读取 N 个实体并将其发送以进行处理。

在我阅读的轮询示例中,轮询用作流程的第一步。就我而言,我想在流程中间实施。

请告诉我如何实现。

感谢任何帮助。 提前致谢。

【问题讨论】:

    标签: spring spring-integration spring-integration-dsl


    【解决方案1】:

    如果您想使用一些外部刺激来触发一些轮询流的开始,请使用控制总线:

    @SpringBootApplication
    public class So63337649Application {
    
        public static void main(String[] args) {
            SpringApplication.run(So63337649Application.class, args);
        }
    
        @Bean
        IntegrationFlow trigger(ConnectionFactory connectionFactory) {
            return IntegrationFlows.from(Amqp.inboundAdapter(connectionFactory, "foo"))
                    .transform(msg -> "@poller.start()")
                    .channel("control.input")
                    .get();
        }
    
        @Bean
        IntegrationFlow control() {
            return f -> f.controlBus();
        }
    
        @Bean
        IntegrationFlow mainFlow() {
            return IntegrationFlows.from(() -> "foo", e -> e
                        .id("poller")
                        .autoStartup(false)
                        .poller(Pollers.fixedDelay(5000)))
                    .handle(System.out::println)
                    .get();
        }
    
    }
    

    【讨论】:

    • @Garry Russel 我们可以将传入消息的有效负载传递给轮询器以供其操作吗?
    • 如果您需要将状态从传入请求传输到 JDBC 轮询器(例如在选择表达式中),那么您需要在启动轮询器之前将其存储在第一个流程中的某个 bean 中。
    • QueueChannel。因此,您将包含该数据的消息发送到通道并启动轮询器以从该通道轮询数据的端点。
    猜你喜欢
    • 2018-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多