Mule Composite source is actually a scope that listen in parallel on different channels for incoming messages. Whenever any of these receivers accepts a message, the Composite scope passes it to the first message processor in the flow, thus triggering that flow.
So, we can say that the Composite source actually accommodate multiple inbound endpoints such that it can trigger the flow if any of the inbound endpoint is triggered.
How to use Composite source in Mule ???
Let’s consider we have a simple Mule flow as following:-
Here , we can see two inbound endpoints are there in the Composite source scope.
So, now our objective is to schedule a task using Quartz endpoint which will trigger the flow at a fixed interval of time and print a message in logger. And at the same way we can use HTTP inbound endpoint to trigger the same flow and achieve the same task !!
So, our Mule config will be as following:-
Here you can see the same log message will be printed by both the endpoints. The reason the Choice router is given to detect the task done by Quartz or HTTP endpoint. So if we hit the browser url, it will display in logger :- “Service started from HTTP”
Testing our application
So, if we run our flow, we will see the following in log :-
Here you can see the same “The task is done“ message is printed in the console by the HTTP endpoint this time. You can also see the message “Service started from HTTP” which confirms the HTTP endpoint has triggered the service. This is detected by our Choice router.
So, here you can see that we can use as many inbound endpoints in our flow to perform the same task. We can accommodate HTTP, File, FTP, JMS etc together in a same flow .
That’s all !!! I hope you liked this !!!