Send is considered as one of the most widely used mediators in ESB. It is built in to the core of the ESB. It performs a fundamental task of any ESB. This fundamental task is to send a message out from ESB.
There are two modes of operation in a send mediator.
If we don't provide an Endpoint it will try to send the message using the wsa:to address of the message. Also if we use a send mediator in the out path of the ESB, without specifying an Endpoint it will send the message as a reply.
If we provide an Endpoint, it will send the message according to the information in the Endpoint. Have a look at the endpoint guide for more details.
Send mediator is the only way to send a message out from the ESB. If you want to forward the message to an Endpoint or to send the reply back this mediator must be used.
The send mediator copies any message context properties from the current message context to the reply message received on the execution of the send operation so that the response could be correlated back to the request. Messages may be correlated by WS-A Message-ID, or even simple custom text labels (see the property mediator and samples).
Note: A send operation may be blocking or non-blocking depending on the actual transport implementation used. As the default NIO based http/s implementation does not block on a send, care must be taken if the same message must be sent and then further processed (e.g. transformed). In such a scenario, it maybe required to first clone the message into two copies and then perform processing to avoid conflicts.
<send/>
If the message is to be sent to one or more endpoints, then the following is used:
<send> (endpointref | endpoint)+ </send>
where the endpointref token refers to the following:
<endpoint key="name"/>
and the endpoint token refers to an anonymous endpoint definition.
Figure 1: Send Mediator Options
You can select the endpoint to be one of the following value.
Send mediator used in in-path and out path
<definitions xmlns="http://ws.apache.org/ns/synapse"> <in> <send> <endpoint> <address uri="http://localhost:9000/services/SimpleStockQuoteService"/> </endpoint> </send> <drop/> </in> <out> <send/> </out> </definitions>
In this configuration first send is used inside a in mediator. As I have mentioned earlier, both request and response will go through the main sequence. But only request messages will go through the child mediators of in and only response messages will go through the out mediator. So the request will be forward to the endpoint with the given address. Response will go through the second send and this send mediator will send it back to the requester.