Home > Back-end >  Spring Integration Wire Tap
Spring Integration Wire Tap

Time:12-21

What is the best way to bind two IntegrationFlows in Java DSL:

  1. .wireTap(someFlow());
  2. .channel("someFlow.input");

In general I have an unidirectional workflow [flow1 -> someFlow -> someAnotherFlow] and so on;

CodePudding user response:

Your question is not clear, but it feels like you want to send a result of one flow to another. Essentially connecting them to a single flow.

The channel() is the best way to do that. The point is that an IntegrationFlow is just a logical container which does not have too much heavy lifting at runtime. The components we need to pay attention are endpoints and channel in between. Even single IntegrationFlow has channels between its handle(), transform(), split() filter() etc. The connection between those endpoint is what important at runtime. And since every single endpoint has its inputChannel to activate, it doesn't mean where and how that endpoint is declared: you still can send a message from any place of your application to that channel. That's a bit of logic behind endpoints and their channel. But I agree that it is much easier to think about business logic as a combination of some unit works, like an IntegrationFlow. So, to connect those units, you really just need to know an input channel where you'd like to send a result of this unit of work.

The wire-tap also could be useful in some scenarios when you want to send the same message at some endpoint to other endpoint and continue in this flow.

So, both your variants are valid, but they may make slight logical difference if it becomes non-linear flow or vise-versa.

See more in docs about flows and wire-taps:

https://docs.spring.io/spring-integration/docs/current/reference/html/dsl.html#java-dsl

https://docs.spring.io/spring-integration/docs/current/reference/html/core.html#channel-wiretap

  • Related