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:
To consume published messages from a queue:
-
Create a VM configuration in a domain, like this:
<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>
-
Publish messages from a second app in the same domain:
<flow name="crossAppRequester">
<vm:publish queueName="sharedQueue" config-ref="sharedVMConfig" />
</flow>
-
Pull messages from the queue after they are published.
<flow name="queueConsume">
<vm:consume queueName="sharedQueue" config-ref="sharedVMConfig" />
<logger />
</flow>
In this example, the Publish and Consume operations point to the same queue (sharedQueue) and the same configuration (sharedVMConfig).