我正在尝试将 Spring Integration 流从 XML 重写为 Java。我想路由通过通道发送的数据:
@Bean(name = "sendData")
public MessageChannel getSendData() {
return MessageChannels.direct()
.get();
}
进入另外两个渠道:
@Bean(name = "sendDataA")
public MessageChannel getSendDataA() {
return MessageChannels.direct()
.get();
}
@Bean(name = "sendDataB")
public MessageChannel getSendDataB() {
return MessageChannels.direct()
.get();
}
取决于他们的可用性。
我有一个RoundRobinRouter
类来确定使用哪个输出通道。它有一个route
返回输出通道名称的方法,例如:
@Component
class RoundRobinRouter {
public String route(Object payload) {
/* implementation */
}
}
请注意,route
方法实现实际上并不使用payload
对象。它以前放置在 XML 配置中:
<int:router method="route" input-channel="sendData"
default-output-channel="sendDataA">
<bean
class="com.example.RoundRobinRouter"/>
</int:router>
我已经尝试过使用 Java DSL IntegrationFlow
:
@Bean
@ServiceActivator(inputChannel = "sendData",
outputChannel = "sendDataA")
public IntegrationFlow routeRoundRobin() {
return router -> router.route(roundRobinRouter, "route");
}
但是我在通话时收到错误“调度程序没有订阅者” sendData.send(payload)
,显然是由以下原因引起的:
org.springframework.expression.spel.SpelEvaluationException: EL1004E:(pos 8): Method call: Method configure(com.example.DataType) cannot be found on com.example.Integration$$Lambda$1/1018103616 type
路由器是我的集成类中唯一的 lambda。