我正在尝试配置一个Spring Batch侦听器,以便向Spring Integration Gateway发送一条消息,用于StepExecution事件。
以下链接说明了如何使用XML
进行配置如何使用Spring Integration DSL进行设置?我发现无法使用DSL配置带有服务接口的网关。
目前我通过实现一个实际的StepExecutionListener来解决这个问题,然后调用一个用@MessagingGateway注释的接口(调用相应的@Gateway方法)以便向通道发送消息。然后我为此频道设置了Integration DSL流程。
使用DSL是否有更简单的方法,避免这种解决方法?有没有办法将Batch侦听器直接连接到网关,就像可以使用XML配置?
干杯, 门诺
答案 0 :(得分:0)
首先,SI DSL只是现有SI Java和Annotation配置的扩展,因此它可以与任何其他Java配置一起使用。当然,XML @Import
也是可行的。
DSL中没有网关配置,因为其方法无法与线性IntegrationFlow
连接。需要为每种方法提供下游流程。
所以,@MessagingGateway
是一种正确的方法:
@MessagingGateway(name = "notificationExecutionsListener", defaultRequestChannel = "stepExecutionsChannel")
public interface MyStepExecutionListener extends StepExecutionListener {}
从另一端@MessagingGateway
解析以及<gateway>
标记解析以GatewayProxyFactoryBean
定义结束。所以,如果你不想引入一个新类,你就可以声明那个bean:
@Bean
public GatewayProxyFactoryBean notificationExecutionsListener(MessageChannel stepExecutionsChannel) {
GatewayProxyFactoryBean gateway = new GatewayProxyFactoryBean(StepExecutionListener.class);
gateway.setDefaultRequestChannel(stepExecutionsChannel);
return gateway;
}
在最新的Milestone 3之后,我有一个想法来介绍nested flows
,当我们可以为流量引入Gateway
支持时。像这样:
@Bean
public IntegrationFlow gatewayFlow() {
return IntegrationFlows
.from(MyGateway.class, g ->
g.method("save", f -> f.transform(...)
.filter(...))
.method("delete", f -> f.handle(...)))
.handle(...)
.get();
}
但是,我不确定它会简化生命,只要嵌套的Lambda只会增加更多噪音并可能违反loosely coupling
原则。