spring-integration - Spring 集成 - @InboundChannelAdapter 轮询
问题描述
我是 Spring 集成的新手。我们正在使用 Spring Integration Annotations 创建我们的应用程序。我已经配置了一个带有 5 秒轮询器固定延迟的 @InboundChannelAdapter。但问题是,一旦我在 weblogic 上启动我的应用程序,适配器就会开始轮询并命中端点,几乎没有消息。我们需要调用一个休息服务,然后触发这个适配器。有没有办法实现相同的?
蒂亚!
解决方案
将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()");
}
}
}
推荐阅读
- javascript - 获取所有相关子元素
- sql - 在 SQL Server 的 CASE 语句中使用 COUNT(*)
- javascript - 如何修复“按钮”交互角色必须是可聚焦的
- java - recyclerview 项目显示在导航抽屉片段中显示空白屏幕
- xamarin - Voip 或语音通话记录 - Xamarin.forms
- groovy - 将表示字符串的键值对转换为列表
- c++ - 赋值运算符重载后的分段错误(核心转储)错误
- android - rxJava2 Single.Just() 总是在主线程中执行。如何让它在另一个线程上执行?
- wordpress - 按 menu_order + 流行度对 WooCommerce 产品进行排序
- javascript - 如果两个相邻的可编辑跨度和光标在中间,html如何决定我在写哪一个?