[英]Spring Integration DSL JDBC inbound channel adapter
我使用 spring 集成从数据库中读取数据。 现在我使用轮询适配器
@Bean
public MessageSource<Object> jdbcMessageSource() {
JdbcPollingChannelAdapter a = new JdbcPollingChannelAdapter(dataSource(), "SELECT id, clientName FROM client");
return a;
}
流动:
@Bean
public IntegrationFlow pollingFlow() throws Exception {
return IntegrationFlows.from(jdbcMessageSource(),
c -> c.poller(Pollers.fixedRate(30000).maxMessagesPerPoll(1)))
.channel(channel1())
.handle(handler())
.get();
}
但我想从其他系统安排我的流程。 有人知道怎么做吗?
从其他系统安排我的流程
从您的流程角度来看,这听起来像是event driven action
。 为此,您应该将JdbcOutboundGateway
与相同的SELECT
。
而且,当然,您应该找到该外部系统的钩子来触发流输入通道的事件。 这可能是任何入站通道适配器或消息驱动适配器,例如 JMS、AMQP、HTTP 等。 取决于您在中间件中已经拥有的内容以及可以将您的应用程序暴露给外部系统的内容。
我想我用自定义触发器解决了这个问题:
public Trigger onlyOnceTrigger() {
return new Trigger() {
private final AtomicBoolean invoked = new AtomicBoolean();
@Override
public Date nextExecutionTime(TriggerContext triggerContext) {
return this.invoked.getAndSet(true) ? null : new Date();
}
};
}
而我的流程:
public IntegrationFlow pollingFlow() throws Exception {
return IntegrationFlows.from(jdbcMessageSource(),
c -> c.poller(Pollers.trigger(onlyOnceTrigger()).maxMessagesPerPoll(1)))
.channel(channel1())
.handle(handler())
.get();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.