嘿,我无法让子流程部分与 java dsl 一起工作。
public IntegrationFlow flow() {
return IntegrationFlows
.from("messageRoutingChannel")
.route("headers." + HeaderKeys.CONNECTION_ID, new Consumer<RouterSpec<ExpressionEvaluatingRouter>>() {
@Override
public void accept(RouterSpec<ExpressionEvaluatingRouter> spec) {
spec.subFlowMapping("connection101",
IntegrationFlows.from("messageRoutingChannel")
.handle(new GenericHandler<String>() {
@Override
public Object handle(String payload, Map<String, Object> arg1) {
System.out.println(payload + " after routing");
return null;
}
})
.get());
}
})
.get();
}
现在,当我将 IntegrationFlow 添加到子流时,我必须给它一个 from()
对吗?我真的不知道该给那里什么。我尝试将 channel()
放在 route()
的正上方,并从该 channel 执行 from()
,但这并没有'也不工作。引用中的大多数示例都使用 lambda,因此那里没有显式的 IntegrationFlows.from()
。只是一个 sf -> sf.handle()
java @Bean public IntegrationFlow routeFlow() { return f -> f .<Integer, Boolean>route(p -> p % 2 == 0, m -> m.channelMapping("true", "evenChannel") .subFlowMapping("false", sf -> sf.<Integer>handle((p, h) -> p * 3))) .transform(Object::toString) .channel(c -> c.queue("oddChannel")); }
from 隐式求值结果是什么?我怎样才能让它在 Java 7 中工作?感谢您的帮助。
最佳答案
首先,用 Java 7 那样编写自己的代码并不是一个好主意。因为它看起来已经像一盘意大利面条了。但是如果您要在那里添加业务逻辑该怎么办?..
对于您的 Java 7 案例,最好使用标准路由设置并基于 channel 制定逻辑,并在 Java 8 升级之前忘记子流程。
无论如何,你可以这样:
spec.subFlowMapping("connection101", new IntegrationFlow() {
@Override
void configure(IntegrationFlowDefinition<?> flow) {
flow.handle(...);
}
})
只是因为 sf -> sf.handle(...)
是内联接口(interface)实现的缩写形式。
关于java - 如何在Java 7中启动spring集成java dsl子流程?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33680503/