One of the joys of Mule 3’s new Message Processor (MP for short) architecture is the power that arises from being able to combine message processors into different patterns. To make this as flexible as possible, the routing message processors that were designed to be used in flows each do a single job, making them highly reusable. This allows you to build up a flow piece by piece, or alternatively modify an already working flow, without having to change its basic structure. Let’s look at an example.
We begin with a very basic flow that reads files from a File endpoint, checks that they’re XML, and and sends their contents to an HTTP endpoint:
That’s fine so long as all orders should be treated alike. But suppose gold customers need to be routed to a faster server? A simple change solves this:
Now we have added a choice router to determine which endpoint to send the order to. If the customer type is set to “gold”, the When clause applies, and the order goes to the gold service. If not, the Otherwise clause applies, and it’s sent to the normal service.
Another wrinkle: our company is adding gold customers so quickly that the gold service is sometimes unavailable, leading to order-processing failures. In that case, we would like to use the normal service as a backup for the gold one.
We have added a first-successful message processor, which attempts to send its message to its children, in order, until one of them processes it successfully. The result it that messages which cannot be processed by the gold service fail over to being processed by the normal one.
One last change: our operations group, which is, as usual, on top of the situation, adds a bank of replicated services for gold members. We no longer need to fail over to the normal service. Instead, we need to be sure that messages processing gets split among the replicated service, to maximize performance.
The round-robin message processor will split processing equally among all of its children, which in this case are the replicated gold services. This should prevent any one of the services from becoming overloaded or creating a bottleneck.
For further information about how to use choice, first-successful, and round-robin, follow the links, or start at the beginning with the pages about flows. Next time out, we’ll investigate a few more of them.