Contact Us 1-800-596-4880

VM Connector Dynamic Routing Example - Mule 4

You can use expressions to have a generic flow that sends messages to different queues depending on certain conditions. For instance, you can make the publish and listen example more interesting by also using an expression in the queueName attribute.

Suppose that the JSON object that you get through the HTTP connector includes a destination object that maps directly to the name of the queue to which you need to write. You can do the following:

<flow name="publish">
    <http:listener path="/json-here" allowedMethods="POST" config-ref="httpListener" />
    <vm:publish queueName="#[payload.destination]">
        <vm:content>#[payload.body]</vm:content>
    </vm:publish>
    <logger/>
</flow>
View on GitHub