---
schema_version: "1"
id: 9b82de15f4212cedf84fc3cae1bc48281b98eb7b57e1fdf89191864af354ef28
title: VM Connector Publish Messages and Get a Response Back Example
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/vm-connector/latest/vm-publish-response.md
canonical_url: https://docs.mulesoft.com/vm-connector/latest/vm-publish-response
source_site: docs.mulesoft.com
content_type: documentation
content_hash: e99a64458e1534ce5fd54e2558cfcc5fb5d08b17804957397a99f882c817e5f0
description: MuleSoft Documentation Site
release: "2.0"
latest: true
---
---
product: VM Connector
version: 2.0
is-latest-version: true
---

# VM Connector Publish Messages and Get a Response Back Example

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

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`.

Building on the [publish and listen example](https://docs.mulesoft.com/vm-connector/latest/vm-publish-listen), suppose you want to send the
response back. You can modify the example like this:

```xml
<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:

```xml
<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>
```

## Error Handling

If the receiving flow fails, this operation will raise a `VM:PUBLISH_CONSUMER_FLOW_ERROR` error.
This error’s description will be that of the original error raised by the flow.

Additionally, a `VM:QUEUE_TIMEOUT` might also be thrown if the receiving flow doesn’t respond in the
expected timeframe.

## See Also

- [Introduction to Anypoint Connectors](https://docs.mulesoft.com/connectors/introduction/introduction-to-anypoint-connectors)

- [Salesforce Help](https://help.salesforce.com)
