In my last Mule project we had to implement a situation that I would call a conversational pattern. Now one could consider almost all communication by messages between systems part of a conversation, but in this case I had the following situation:
- I offer a message containing an order line to an application to add it to a certain order
- I receive back a ‘response’ message with one of the following responses:
- A. Order line is added to order
- B. Order to add orderline to, is not found
- C. Order status does not allow adding new orderline
- D. Some other functional exception
- Based on the response I had to react differently:
- In case of situation A and D the conversation was over
- In situation B and C however, I wanted to modify the original message that was sent with the orderline and resend it to the application.
- the processing of the original message and combining of the original and the response message
- determine the response and react to that by altering the original message and resend it
The problem with this situation was that the original message was taken from a JMS queue and sent by HTTP to the application, so at the time I received the response from the HTTP endpoint and interpreted it, I didn’t have access to the original message anymore. So while thinking about the best way to solve this issue I was pointed by the Mule forum to use a ‘component binding’ for this. I wasn’t familiar with this functionality of Mule but it turned out to be exactly what I needed!
Next are the most important pieces that should give you a good hint how to solve this if come across the same pattern. The part of the mule-config.xml where this conversation starts:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <service name="OrderService"> <inbound> <vm:inbound-endpoint path="order-service"/> </inbound> <outbound> <chaining-router> <vm:outbound-endpoint path="order-post-service" synchronous="true"> <transformers> <byte-array-to-string-transformer /> </transformers> </vm:outbound-endpoint> <vm:outbound-endpoint path="process-response"> <object-to-string-transformer/> <transformer ref="JaxbXmlToObject"/> </vm:outbound-endpoint> </chaining-router> </outbound> </service> |
What I do here (as usual with complex problems) is that I divided them in two less complex situations:
In the next to posts I will dive deeper into the details of each of these steps.
Pingback: Example of using Component Binding in Mule2 (part 2) | Redstream Blog
Pingback: Example of using Component Binding in Mule2 (part 2) | Redstream Blog
Pingback: Example of using Component Binding in Mule2 (part 3) | Redstream Blog
Pingback: Example of using Component Binding in Mule2 (part 3) | Redstream Blog