[英]Spring Integration - DSL - Split or Fork
我想為以下流程創建IntegrationFlow流程。
@Bean public IntegrationFlow buildCart() { return f -> f.handle(validate, "buildPreCheck") .handle(preProcessProcessor) .handle(getOffersProcessor) .handle(buildItems) **.wireTap(log())** .handle(validateItems) .handle(deliver); }
編輯:
嗨Artem,我添加了Wire Tap,如下面的代碼所示。 它仍然將WireTap節點排除為Sequencal並等待該節點。
請幫助它成為Aysnc節點。
@Bean
public IntegrationFlow log() {
return f -> f.handle(auditProcessor).channel("nullChannel");
}
@ServiceActivator
@Description("Call and get the Offers Request")
public void getDetails(Message<Context> message) throws InterruptedException {
log.info("getDetails-Sleep-Start");
Thread.sleep(3000);
log.info("getDetails-Sleep-End");
}
使用Spring Integration Java DSL,我們都缺少Spring Integration中一個非常重要的組件是MessageChannel
。 事實上,只要我們需要的不僅僅是默認的DirectChannel
,渠道就可以添加到流程中。 對於異步執行,我們有一個ExecutorChannel
。 但是在我們進行分叉流程之前,我們需要以某種方式跳到那里而不會破壞主要的流程。 就EIP而言,這稱為Wire-Tap: https : //www.enterpriseintegrationpatterns.com/patterns/messaging/WireTap.html 。
Spring Integration Java DSL建議在流程中使用類似.wireTap()
運算符的實現。 審計邏輯可以在抽頭子流程中或通過渠道實現,但不要忘記ExecutorChannel
!
您可以在參考手冊中查看更多信息: https : //docs.spring.io/spring-integration/reference/html/java-dsl.html#java-dsl-wiretap
UPDATE
該
.handle(buildItems)
.wireTap(log())
是正確的方法:您將審核buildItems
的結果並繼續下一步。
必須像這樣修改log()
:
@Bean
public IntegrationFlow log() {
return f -> f.channel(c -> c.executor(taskExecutorBean())).handle(auditProcessor).channel("nullChannel");
}
注意c.executor()
。 這樣我們就可以為log()
子流添加異步切換。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.