---
schema_version: "1"
id: c27c6373cab522b5fabc53a84139a2a2dfb6f081012bdc40dbd4af7deb439337
title: VM Connector Send Messages across Different Apps Example
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/vm-connector/latest/vm-publish-across-apps.md
canonical_url: https://docs.mulesoft.com/vm-connector/latest/vm-publish-across-apps
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 91c2f10b91261c5bb9e7031a473878d966857e6f23288258376e3c0945470e4e
description: MuleSoft Documentation Site
release: "2.0"
latest: true
---
---
product: VM Connector
version: 2.0
is-latest-version: true
---

# VM Connector Send Messages across Different Apps Example

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

The following examples show two ways to send messages across different apps:

- Use a Listener to receive the messages from the first app and a Publish operation to feed the
  received messages to a second app.

- Use a Publish operation in a second app to push messages to the queue of messages, and a Consume
  operation to consume the messages.

In both cases, the two apps must be in the same domain.

## Publish Messages to a Second App

1.  Create a VM configuration in a domain, like this:

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

2.  Place a listener in an app in the same domain:

    ```xml
    <flow name="crossAppListener">
    	<vm:listener queueName="sharedQueue" config-ref="sharedVMConfig" />
    	<logger />
    </flow>
    ```

3.  Publish messages from a second app in the same domain:

    ```xml
    <flow name="crossAppRequester">
      <vm:publish queueName="sharedQueue" config-ref="sharedVMConfig" />
    </flow>
    ```

In this example, the Listener and Publish operation point to the same queue (`sharedQueue`) and the
same configuration (`sharedVMConfig`).

## Pull Published Messages from a Queue

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.

To consume published messages from a queue:

1.  Create a VM configuration in a domain, like this:

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

2.  Publish messages from a second app in the same domain:

    ```xml
    <flow name="crossAppRequester">
      <vm:publish queueName="sharedQueue" config-ref="sharedVMConfig" />
    </flow>
    ```

3.  Pull messages from the queue after they are published.

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

## See Also

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

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