Free MuleSoft CONNECT Keynote & Expo Pass Available!

Register now+
Nav

Example: To Send Messages across Different Apps

Instead of using the <vm:listener> message source, you can consume messages in a VM queue through the <vm:consume> operation.

This operation can consume messages on demand, allowing you to:

  • Dynamically consume from different queues depending on a certain condition.

  • Have a tighter control on the rhythm at which the app consumes messages.

You can also send messages across apps by using Mule domains. Unlike Mule 3.x in which domains were reserved to a handful of supported components, starting in Mule 4, every connector can be placed in a domain.

So, you can create a VM configuration in a domain like in this:


       
    
1
2
3
4
5
6
7
8
9
10
11
<mule-domain xmlns="http://www.mulesoft.org/schema/mule/domain"
             xmlns:vm="http://www.mulesoft.org/schema/mule/vm"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://www.mulesoft.org/schema/mule/vm http://www.mulesoft.org/schema/mule/vm/current/mule-vm.xsd
               http://www.mulesoft.org/schema/mule/domain http://www.mulesoft.org/schema/mule/domain/current/mule-domain.xsd">

    <vm:config name="sharedVMConfig">
      <vm:queue queueName="sharedQueue" queueType="PERSISTENT" />
    </vm:config>

</mule-domain>

Then you place a listener in an application of the same domain:


       
    
1
2
3
4
<flow name="crossAppListener">
        <vm:listener queueName="sharedQueue" config-ref="sharedVMConfig" />
        <logger />
</flow>

Then you publish messages from a second application, also of the same domain:


       
    
1
2
3
<flow name="crossAppRequester">
        <vm:publish queueName="sharedQueue" config-ref="sharedVMConfig" />
</flow>

Notice how both the listener and publisher point to the same configuration defined in the domain.