私はこの仕事をするために数日間苦労しています。私は何を達成しようとしていることは、メッセージの内容に基づいて、メインフローから、(統合の流れです)異なるサブフローを呼び出し、サブフローを終了し、メインフローに戻るには後にすることです。仕上がりのものにしてメインフローに戻るには、特定のクラスにそのような委任の責任。その責任はまた、いくつかのステップを必要とするので、そのだけでなく、フローとして実装することができます。ここに私の主な流れは以下のとおりです。
public IntegrationFlow processingFlow(
MessageChannel eventIn,
MessageChannel eventOut,
ChangedEventsLoader changedEventsLoader,
CalculatorRouter calculatorRouter) {
return IntegrationFlows.from(eventIn)
.handle(changedEventsLoader)
.route(
CalculatorRouter::getSportId,
CalculatorRouter::routeCalculation)
.channel(eventOut)
.get();
}
ここでは、ルータの実装は次のとおりです。
@Service
@AllArgsConstructor
public class CalculatorRouter {
private final MessageChannel eventOut;
public RouterSpec<Integer, MethodInvokingRouter> routeCalculation(
RouterSpec<Integer, MethodInvokingRouter> mapping) {
return mapping
.channelMapping(1, "subflowCalculationChannel")
.defaultOutputToParentFlow();
}
public Integer getSportId(Event event) {
return 1;
}
@Bean
public MessageChannel subflowCalculationChannel() {
return MessageChannels.direct().get();
}
}
そして、ここで1つのサブフローの例です。
@Configuration
@AllArgsConstructor
public class CalculatorExample {
@Bean
public IntegrationFlow calculateProbabilities(MessageChannel subflowCalculationChannel) {
return IntegrationFlows.from(subflowCalculationChannel)
.<Event>handle((p, m) -> p * 2)
.get();
}
}
トラブルは、主流といくつかの接続そのサブフローミスです。私は一部のルーティングにdefaultOutputToParentFlowを()を用いることにより解決しようとしたが、それは十分ではありません。
いくつかのバージョンを起動し、我々は注釈やXMLの標準構成でのJava DSLルータの動作を整合させることを決定しました。私たちはルータに送るのであれば、我々はそこからの応答を期待することはできません。私たちは、サブフローからの出力としてチャンネルを続行することができます。
あなたのケースでは、あなたが持っている.channel(eventOut)
メインフローに。だから、すべてのルーティングサブフローは、このチャネルに正確に答える必要があります。
.<Event>handle((p, m) -> corners1H2HCustomBet.getCalculation(p))
.channel(eventOut)
.get();
私が思うに.defaultOutputToParentFlow();
、あなたがデフォルトのマッピングを持っていないので、ちょうどあなたのために何がありません。そして、それはすでに少し別の話である:それは他のマッピングのための任意の効果を持っていません。
また、このJavaDocのに注意を払います:
/**
* Add a subflow as an alternative to a {@link #channelMapping(Object, String)}.
* {@link #prefix(String)} and {@link #suffix(String)} cannot be used when subflow
* mappings are used.
* <p> If subflow should refer to the external {@link IntegrationFlow} bean and
* there is a requirement to expect reply from there, such a reference should be
* wrapped with a {@code .gateway()}:
* <pre class="code">
* {@code
* .subFlowMapping(false, sf -> sf.gateway(evenFlow())))
* }
* </pre>
* @param key the key.
* @param subFlow the subFlow.
* @return the router spec.
*/
public RouterSpec<K, R> subFlowMapping(K key, IntegrationFlow subFlow) {
あなたのチャンネルベースのルーティング設定に関連するが、将来的に有用である可能性があるわけではありません。
更新
ここでのサンプル(Kotlin)でsubFlowMapping
、メインフローに戻ると:
@Bean
fun splitRouteAggregate() =
IntegrationFlow { f ->
f.split()
.route<Int, Boolean>({ o -> o % 2 == 0 },
{ m ->
m.subFlowMapping(true) { sf -> sf.gateway(oddFlow()) }
.subFlowMapping(false) { sf -> sf.gateway(evenFlow()) }
})
.aggregate()
}
@Bean
fun oddFlow() =
IntegrationFlow { flow ->
flow.handle<Any> { _, _ -> "odd" }
}
@Bean
fun evenFlow() =
IntegrationFlow { flow ->
flow.handle<Any> { _, _ -> "even" }
}