首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring Integration - @InboundChannelAdapter轮询

Spring Integration - @InboundChannelAdapter轮询
EN

Stack Overflow用户
提问于 2019-12-24 21:31:28
回答 1查看 360关注 0票数 0

我是Spring Integration的新手。我们使用Spring Integration注解创建我们的应用程序。我已经配置了一个@InboundChannelAdapter,轮询器的固定延迟为5秒。但问题是,只要我在weblogic上启动我的应用程序,适配器就开始轮询并访问端点,而实际上没有任何消息。我们需要调用rest服务,然后触发此适配器。有没有办法实现这一点呢?

蒂娅!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-24 22:51:02

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

代码语言:javascript
复制
@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()");
        }
    }

}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59469573

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档