This article by Danushka Menikkumbura illustrates adding persistance to the Apache Synapse ESB [1 [0]].
Table of Contents
1. Introduction [0]
2. Who should Read this Article? [0]
3. The Synapse Persistence Model (Queuing Model) [0]
3.1. Why JMS? [0]
3.2. Why ActiveMQ? [0]
4. How to Configure Synapse JMS Persistence Model [0]
4.1. JNDI Configuration [0]
4.2. Axis2 Configuration [0]
4.3. Synapse Configuration [0]
5. Running Sample Application [0]
5.1. The Use Case [0]
5.2. How to Run Sample [0]
6. Conclusion [0]
1 [0]] is a simple, light-weight and high-performance Enterprise Service Bus (ESB). Synapse outperforms most the leading ESB's and comes with a rich set of features that caters for most business requirements [1 [0]]. However, Apache Synapse does not posses a mechanism to support message persistence within itself. When it comes to reliable messaging, being able to persist incoming messages is crucial - especially in one-way communications.
Why the one-way case is so special? In a two-way communication channel (i.e. request/response pattern), as the sender awaits for response, he is able to redo any requests in case the messaging hub goes down. Additionally, in a request/response pattern, it is really unlikely that you send a burst of requests and await for responses. So for the most part, it is a single request/response invocation taking place at any given time and thus having a persistence mechanism in the middle may not help so much in the two-way scenario. But when it comes to one-way communication channels, and specially if it is a fire-and-forget kind of message exchange pattern, having a persistence mechanism in the middle would add lots of value to a messaging engine. Typically, a message sender may not re-send a message, unless there is end-to-end message reliability support at the application-layer. As such, should Synapse display support for message persistence, it would greatly enhance its capability for reliable messaging.
There are different flavors of persistence models such as queuing model, flat file model, relational database model, object-relational database model, etc. Queuing model is preferred over other alternatives as it preserves the order of messages automatically. In Synapse, we can get the job done using it's JMS transport, a JMS provider and a combination of two proxy services. We can use ActiveMQ as our JMS provider. This article explains how to achieve persistence in Synapse using the queuing model in detail. Here we go ...
2 [0]],configuring Synapse's JMS transport [3 [0]] and the concept of proxy services in Synapse [4 [0]] so that you'd be able to grab whatever explained here with ease. But either way, feel free to read through and use this as a reference manual to add persistence to Apache Synapse using a queuing model.
5 [0]] so that we can make Proxy1 accept messages that are coming over any transports supported by Synapse. Proxy1 has an endpoint that performs message queuing (JMS), to allow a message received by Proxy1 to be dumped in a queue. We can use ActiveMQ broker to provide us with a JMS queue. This queue is important for two reasons:
(1) It helps FIFO message flow so that message order is preserved.
(2) Persistence can be built into the queue to handle message persistence in the middle.
Then, Proxy2 that reads messages from the queue comes into action and pops messages from the queue and pumps them through its in-sequence. We can configure Proxy2 to have desired message mediation functionality.
3 [0]] to learn how to configure its JMS transport. Here we are going to use default connection factory, so that we will be having the following JMS configuration:

Here the connection factory name has to be the factory name we defined in jndi.properties file. And of course it has to be of type queue.
6 [0]] to see how you get the stockquote client to work with Synapse.
We send a number of requests for a quote over HTTP through our Synapse instance to the SimpleStockQuoteService hosted on Simple Axis2 server. Then we stop our Synapse server and run it again. As soon as it comes back up, we should be able to see persisted messages being received by the actual service endpoint.
7 [0]].
(3) The message flow from client to the actual service endpoint happens in a fraction of a second, that you can not shutdown your Synapse server before all messages pass through it. So to simulate this scenario, we will do the following trick.
(3.1) Replace your synapse.xml with the attached synapse.xml, change the name of its second proxy to something else (say TempProxy) and start your Synapse server.
(3.2) Now start your Simple Axis2 server.
(3.3) Send a couple of requests as follows.
ant stockquote -Dtrpurl=http://localhost:8280/soap/Proxy1 -Dmode=placeorder
(3.4) At this point you cannot see any message being received by the actual endpoint.
(3.5) Now stop your Synapse server, change the name of the second proxy back to its original name(i.e.Proxy2) and then start the server again.
(3.6) You should be able to see the messages you sent earlier being received by the actual endpoint
Synapse Home Page [1]
[2] - Sun Java JMS Tutorial [2]
[3] - Configuring Synapse JMS Transport [3]
[4] - Synapse Proxy Services Samples [4]
[5] - Synapse Transport Bridging Samples [5]
[6] - Synapse Quick Start [6]
[7] - Download ActiveMQ [7]