In certain cases, you might want to get a response back. The publish-consume operation handles this by waiting for the message to be processed on the other end and providing the response. The operation is otherwise exactly the same as publish.
<flow name="publish">
<http:listener path="/json-here" allowedMethods="POST"
config-ref="httpListener" />
<vm:publish-consume queueName="#[payload.destination]" config-ref="vm">
<vm:content>#[payload.body]</vm:content>
</vm:publish>
<logger/>
</flow>
In the next example, notice that the <vm:listener> source embeds a DataWeave expression that builds the response.
Suppose that you want a response in a predefined JSON format, such as simple one with a body and origin value:
<flow name="listener">
<vm:listener queueName="queue" config-ref="vm">
<vm:response>
<vm:content><![CDATA[#[
%dw 2.0
output application/json
---
{
"origin": "Awesome Mule 4 VM connector",
"body" : payload
}]
]]>
</vm:content>
</vm:response>
</vm:listener>
<flow-ref name="theIntegrationLogic" />
</flow>