首页 > 解决方案 > Spring 集成 - @InboundChannelAdapter 轮询

问题描述

我是 Spring 集成的新手。我们正在使用 Spring Integration Annotations 创建我们的应用程序。我已经配置了一个带有 5 秒轮询器固定延迟的 @InboundChannelAdapter。但问题是,一旦我在 weblogic 上启动我的应用程序,适配器就会开始轮询并命中端点,几乎没有消息。我们需要调用一个休息服务,然后触发这个适配器。有没有办法实现相同的?

蒂亚!

标签: spring-integration

解决方案


autoStartup属性设置为false并使用控制总线来启动/停止它。

@SpringBootApplication
@IntegrationComponentScan
public class So59469573Application {

    public static void main(String[] args) {
        SpringApplication.run(So59469573Application.class, args);
    }

}

@Component
class Integration {

    @Autowired
    private ApplicationContext context;

    @InboundChannelAdapter(channel = "channel", autoStartup = "false",
            poller = @Poller(fixedDelay = "5000"))
    public String foo() {
        return "foo";
    }

    @ServiceActivator(inputChannel = "channel")
    public void handle(String in) {
        System.out.println(in);
    }

    @ServiceActivator(inputChannel = "controlChannel")
    @Bean
    public ExpressionControlBusFactoryBean controlBus() {
        return new ExpressionControlBusFactoryBean();
    }

}

@MessagingGateway(defaultRequestChannel = "controlChannel")
interface Control {

    void send(String control);
}

@RestController
class Rest {

    @Autowired
    Control control;

    @PostMapping("/foo/{command}")
    public void trigger(@PathVariable String command) {
        if ("start".equals(command)) {
            control.send("@'integration.foo.inboundChannelAdapter'.start()");
        }
    }

}

推荐阅读