Here I have 3 different flows and I'm using spring integration dsl. Let's assume we have prepared an object in flow 1 and I want to pass that object to other flows without disturbing the actual payload that's coming from the gateway. So I just want to add the object somehow in somewhere but not changing the actual payload so that I can use that object in subsequent flows. I can pass that in header but will that be correct to send a big object in header?
Here I'm using scatter gather pattern with three parallel flows.
@Bean
public IntegrationFlow flow() {
return flow ->
flow.handle(validatorService, "validateRequest")
.split()
.channel(c -> c.executor(Executors.newCachedThreadPool()))
.scatterGather(
scatterer ->
scatterer
.applySequence(true)
.recipientFlow(flow1())
.recipientFlow(flow2())
.recipientFlow(flow3()),
gatherer ->
gatherer
.releaseLockBeforeSend(true)
.releaseStrategy(group -> group.size() == 2))
.aggregate(lionService.someMethod())
// here I want to call other Integration flows
.gateway(someFlow())
.to(someFlow2());
}
//Here in this flow I'm calling prepareCDRequestFromLionRequest method in the handle(). This method returns an object1 which is one of the payload(among 3) that will be used after aggregation but I want to prepare another object2 in this method and somehow want to send that object2 to the someFlow() or someFlow2() but I want object1 as a payload.
@Bean
public IntegrationFlow flow1() {
return flow ->
flow.channel(c -> c.executor(Executors.newCachedThreadPool()))
.enrichHeaders(h -> h.errorChannel("flow1ErrorChannel", true))
.handle(cdRequestService, "prepareCDRequestFromLionRequest");
}
//same way I have flow2 and flow3
//validateRequest method
public Object1 validateRequest(LionRequest lionRequest) {
lionValidationHelper.validateRequestAttributes(lionRequest);
// validation code goes here after creating a new request object which will go to the parallel flows
Object1 obj1 = someLogicTocreateTheObject1
Object2 obj2 = someLogicTocreateTheObject2
return object1;
}
*UPDATE - Now as u see above I'm sending object1 as a payload but I need object2 to be sent from here somehow so that I can make use of this object2 in other subsequent flows. This Object2 is a POJO and having different fields so in other flows I'll be getting relevant information which I'll be setting to it's fields. And finally I'll be getting an object which then I'll be using in someFlow(). So I want object to be passed and enhancing that object in different flows that I have.
Or let's suppose after validateRequest I want to create an object and want to pass that to the parallel flows/someFlow somehow but I don't want to hamper the payload that will be coming to the flows. By using header it's achievable but is there a different way to achieve this?