So what is Esper and how can it work with Synapse?
Basically, you Esper will look for patterns in a set of messages. When it spots a pattern, it creates an event. Because Esper supports XML and XPath through DOM, it fits perfectly with Synapse. Without writing any code you can configure it to look at SOAP or XML messages as they flow through Synapse. When a query "hits" it sends a new message into Synapse. That message can then be sent out or logged. The message can either be an exact copy of one of the messages that came into Synapse or it can be a set of tag/values extracted by Esper.
Esper uses a query language just like SQL except called EQL. Because there aren't any tables, instead you define the root element of the XML and give that a name. You can also pass in a schema. Now you can do selects on that just like it was a table.
It took me less than a day to get it working. In fact, the first message worked pretty soon. It took me longer to get XPath working. I suspect there is a bug in Esper and I've raised a JIRA. I wasted a bit of time on that. I also had to learn Esper, but that turned out pretty simple. I certainly haven't got all the features working, and I only tried a really simple example.
Basically what I did was create a Synapse class mediator. You can add it to your synapse.xml like this:
<class name="org.fremantle.esper.EsperMediator">
value="c:/synapse-1.0/repository/conf/esper.conf.xml"/>
<property name="statement"
value="select symbol from StockQuoteEvent"/>
When an event hits that matches the statement, the event will be re-injected into Synapse with the To address as specified. You can then either mediate it or have a rule to send it out. If you specify "select *" then the whole message will be sent on.
If you specify parts using an XPath, then I simply create a little XML that captures those:
e.g.
<entry key="symbol">IBM</entry>
</event>
The Esper configuration that we pointed to above needs to define the XML objects that you are going to see. That allows you to query on them.
<event-type alias="StockQuoteEvent">
<xml-dom root-element-name="getQuote"
default-namespace="http://services.samples/xsd"/>
</event-type>
</esper-configuration>
I'd also like to create a XMLMediatorFactory so this can be plugged in a little more neatly - for example having the Esper config inlined in Synapse.xml. And I'd like to make it more robust and support things like patterns and some of the more advanced Esper features.
Despite that, I think this is enough to get going and play with it. I'm really pleased. The combination of the Synapse performance with Esper's flexibility is a cool combination.
4 comments:
Hi Paul,
I am trying to get an ED-SOA (Web Services) architecture implemented as part of my PhD. When I looked at a WS request on the wire, it had HTTP headers before the SOAP envelope - this caused Esper a problem (as it was not a valid XML document). Are these HTTP headers not present when the msgs are flowing through Synapse? (hence Esper will detect them).
The architecture I am thinking of is Service A on Machine A posts an event onto the ESB (Synapse) i.e. this is a Web service request. Service B on Machine B detects the event, fires and posts its response back into Synapse from where Machine A detects it. It appears to me that a pub/sub (JMS) would be the best protocol to use? Does this sound possible? If I used a HTTP request/reply model, would that work? I believe HTTP has issues with NATing... Also, I would be interested in implementing both RESTful and SOAP web services?
Thanks,
Sean.
Sean
Synapse handles the HTTP headers and also the SOAP Enveloping. There is basically a utility method getXMLPayload, which returns the XML body of the message, which can then be handed to Esper.
You could do all this as HTTP request response, or you could do a combination of HTTP and JMS. For example the initial stream could be HTTP or SOAP, and the events that Esper generates could be sent to a JMS Topic. Alternatively you could have Synapse and Esper transparently "sniffing" an existing WS interaction and then sending new HTTP messages when it creates a new event.
Finally, Synapse supports both SOAP and pure XML/HTTP so you could do the RESTful approach as well.
Paul,
Thanks for the reply. Sorry for the delay in getting back - work pressures. In essence what I want to do is an ED-SOA where my requests and replies from the WS clients and Web Services are asynchronous events (pure EDA).
My previous implementation of a WS was on Axis 1.2. All my messages had Http headers. If I use Axis2 (bundled with Synapse I believe) will I be able to send out my WS requests in an asynchronous fashion? Can Http be used asynchronously? If I use HTTP does that mean I need to use WS-Addressing for the reply? How will Esper fire and invoke the Web Service if there are http headers (how does Synapse decide when to strip the http headers from msgs and then pass to Esper?).
Can I use pub-sub? Tom Bernhardt felt JMS would be better suited to EDA as it supports pub-sub. What implications does that have?
As you can see I am trying to get my head around the detailed path to/from client/ws and where Synapse/Esper/Axis all fit in.
My email is skennedy@ait.ie if you would prefer not to use the blog.
Sorry for all the q's. Appreciate the help.
Sean.
Hi Paul & Sean,
I've been reading through the post and the comments since I am looking to implement a similar EDA pattern using an open source ESB.
I have figured out the way to do so in ServiceMix, using the JMS Binding Components that it offers to publish the consumers' requests to a queue, to which the providers will be subscribed to.
However, this implies crossing the JBI domain (the boundaries of the JBI containers), which doesn't seem an sufficiently attractive solution.
Plus, defining the equivalent of in-out sequences in ServiceMix is a real headache! (The best solution I've found is to use the Pipeline EIP or Static Routing Slip pattern).
Thus, I am really researching on the suitability of WSO2 for this scenario. So far, I've loved WSO2's sequence designer, it makes life so much easier!
Therefore, I would like to get at much information on how to use WSO2 for EDA... I am reading Sean's questions and they coincide with me, so I was wondering if you could send me the private reply you must have sent to Sean...
My email address: raul [dot] kripalani [at] atosorigin [dot] com.
Thanks a lot!
Post a Comment