【问题标题】:Spring Integration - DSL - Split or ForkSpring 集成 - DSL - 拆分或分叉
【发布时间】:2018-09-01 02:05:49
【问题描述】:

我想为以下流程创建一个 IntegrationFlow 流程。

  1. 从开始到交付是同步流程。
  2. 如何从 Build Items 和 Validate Items 中提取/派生异步结束节点。

	@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");
}

【问题讨论】:

  • 你肯定需要在我的回答中添加评论,所以我会收到通知。否则你的编辑会被忽略。

标签: java spring-integration dsl


【解决方案1】:

使用 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

更新

.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() 子流程添加了异步切换。

【讨论】:

  • 请在我的回答中找到更新。
  • 非常感谢 Artem。
猜你喜欢
  • 2023-02-24
  • 1970-01-01
  • 1970-01-01
  • 2020-11-06
  • 2020-04-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-17
相关资源
最近更新 更多