Welcome back. In this video, we'll understand about what is scatter gather component. Before that, let me tell you my use case. Actually, I am working on this project, scatter gather start, where you have three flows. First flow, you can see that this is a flow, she's making REST API call. Sure correctly.
Yep, the first flow, you can see this is making a REST API call to get all the products GET request to slash products. So this will give me Jason of all the products. Now this transform method is converting that to Java. So I'll be getting list of products in Java format. So again, the second flow you can see it's making a soap request called Get out products. And the Transformers just converting the XML to list of products again in Java and this DB flow is firing a query Select star from products again, this transformer this converting to chow cycler three flows, each flow output will be a list of products.
Now what I want is I want another flow to make concurrent requests to all this flow by spinning up three threads wait until all three threads complete. Then gather the responses of all the three flows and then give it so that's where we can use scatter gather. Let us see First of all, I will drag and drop one more flow with a stipulation of Okay. I'll configure it with path slash all. Okay, then from my core module, I can drag and drop, scatter gather component. Okay.
Then I want to call three first concurrently, so I'll drag three flow references after scatter gather. Three flow references means actually where conflict three routes to scatter gather. Okay, we had to be very careful at drag and drop. Once the line comes at Yep, it is again and then drag and drop Presley. Yes. So the first floor reference I'll make it a point to say the flow.
I'll rename the flow also as the same name. Okay. Then second flow I'll map it to rest flow, the same name. Third flow reference, I'll map it to sub flow and the same display name. Okay? So I can't forget scatter gather three routes with three four references.
The output after scatter gather will be a list this Stop say three from three flows. Actually what scatter gather will do is since there are three routes, it has been of three threads and each thread will execute the floor reference. Concurrently the scatter gather will wait till all threats join, gather the response and give it back. So, after scatter gather the payload will be list of phase three in this case. So, now what I want is I want to transform the data using transform method so, drag and drop here, if you see the payload the rest of the the input for this transform message does the payload is of size three, right. payload is an object which contains identity objects Each object serving c payload is an array.
And here payload is anything you saying, Here payloads array, sexually, I want to get this nested payloads. Each payload is actually a list item in there. So I want to flatten and get one single list. Right first plus giving a list second first giving a list third, first giving a list. I want to flatten. So there's a simple function dw will call us flatten, flatten and you payload.
But where does the law is not alleged flatten accepts less. So I want all the necessary pillars dot dot payload. So dot dot means we'll get all the nested elements with name. So let's get into the list. That's how now I want The transformer to convert back to JSON so that I can display it on the browser. Yep, I made it.
Oh, let me run this. Okay, it's traffic. So, I try to request a local machine browser. So you request to localhost 8081 slash All right. I should get a list of all the objects from all the floors I got 12 that I got out. So if you see here in my console, everything is locked.
Right. And you can see the thread and there are three threads which chart which actually concurrently executed to get the result and scatter gathers. We waited until all three threads completed and it gathered. Okay, so what will happen if one of the one of the flow throws an exception? Let us see. What I'll do is I want my soap web service call to fail.
So I'll go and stop the server that is running. So that the flow will fail. Let us see what happened. The flow phase is very important for certification. ship and give. Refresh.
Yeah, I got an error. is it so important? Remember, if one of the route of scatter gather phase, scatter gather, also throw an exception. Please remember this, right? Now, if I double click on scatter gather, the total scatter gather was one of three threats in this case, and we will wait for all three that's joining. I want to configure timeout for reading, I can configure the timeout.
If I don't configure it will wait until the response comes. And maximum concurrency how many maximum threats can be pinned off concurrently? I can do here if I want. So these are the configurations ready to scatter gather. It's actually very scatter gather in core module. Yeah, here it is.
Right. Bye. Yeah there are some are some more some more also, there's one more thing for us first successful part of this fast successful let us try to understand the drag and drop workflow here yep first successful also can take multiple routes. So, I can drop flow references Yeah. So fast successful also can is taking multiple routes just like scatter gather, but what happens is whenever a request comes to first successful it invoke the first flow first round. If that is giving if that is not giving any exception, then the next flows next routes will not even executed.
Because the first route was successful. It was not throwing anything exception, but if first floor reference the first route throwing an exception, then the second flow second route will be executed. If this user, if this piece responds properly, third route will not be executed. So like that the first successful router will route and make sure that the first route fails, then secondary to the second route also fails. Third route is execute. So the first successful route responses given So, there are some there might be some use cases where you want failover.
So, let's assume that you have two soap endpoints for the same service maybe to serve web services, two endpoints that means two machines on which same soap web services running. You want the first for reference to always point to One of the you are if that fails then you want second as fallback if that also fails third of the fallback. In such cases we can use first successful. Okay. Now we want to support first successful surely one more interesting thing. There is one more thing also here in core until successful until successful also is something like us cope with drag and drop until successful actually is until successful what I can do is I can write any logic right now let's say drag and drop for reference.
Okay, and 40s until successful I can specify SR max Number of retries by default is five and milliseconds with 460,000 milliseconds. That means what whenever request comes to this until successful score, gateway aka for reference, if that is throwing an exception, then until successful, we'll wait for 60,000 milliseconds. And again, retry. Again retry invoking the for reference. Again, it fails. Again, wait for 60,000 milliseconds, again to try until the maximum number of retries are exhausted.
So if you want to actually retry executing some logic for a fair number of times, and if you want to wait before retrying, then you can use this until successful cope. Right. So that's some About how to use scatter gather until successful and also first unsexy first successful Excel See you next video. There is a lab which you can do for this scatter gather. Just go through this document and complete scatter gather document. I'll see you next video.