---
schema_version: "1"
id: 6b500d495c63efad29f4fcbd8de6b0d42e36f6a98d296d4286c27bf114b84856
title: "Tutorial: Create a Queue and Send Messages to It"
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/mq/mq-tutorial.md
canonical_url: https://docs.mulesoft.com/mq/mq-tutorial
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 2f9239e2d71c7abc4645d91ad82b0cf17d5bc2f056ab6f07df7d8b790e2fa9f0
description: MuleSoft Documentation Site
latest: true
---
---
product: MQ
---

# Tutorial: Create a Queue and Send Messages to It

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

Use this tutorial to get started with using Anypoint MQ to send messages to and retrieve messages
from a _queue_, which is a temporary storage area for a message.

In this tutorial, you:

1.  [Create a queue](#create-queue) in Anypoint MQ.

2.  [Send messages to the queue](#send-messages), verify that they arrived, and view the message
    payload.

3.  [Configure a connected app](#configure-connected-app) and use the ID and secret to configure
    Anypoint Connector for MQ (Anypoint MQ Connector) version 4.x.

    To use connected apps with Anypoint MQ, you must use Anypoint MQ Connector 4.x for Mule 4. If
    you are using Anypoint MQ Connector version 3.x or earlier, configure a client app instead. For
    information, see [Configuring Client Apps](https://docs.mulesoft.com/mq/mq-client-apps).

4.  [Create a Mule 4.x app in Anypoint Studio 7.x](#configure-mule-4-studio), configure Anypoint MQ
    Connector, and test the connection.

## Before You Begin

Before you begin this tutorial, you must have:

- Familiarity with [Anypoint MQ Glossary](https://docs.mulesoft.com/mq/mq-glossary)

- A paid Anypoint Platform package or subscription with the Anypoint MQ integration add-on

  Contact your account team for information.

- Anypoint Studio installed on your system

- A [`curl` command line tool](https://curl.se/) for testing

  This tutorial uses the HTTP Listener trigger to initiate Anypoint MQ Connector access and a `curl`
  command to submit REST API commands to the Anypoint MQ Broker API.

## Step 1. Create a Queue

First, you create a queue, send messages to the queue, verify that the messages arrived, and view
the message payload.

To create a queue:

1.  Sign in to Anypoint Platform and click **MQ** in the navigation menu.

2.  If you want to test the queue in Anypoint Studio 7.x, switch to any environment except Design.

    For example, click the environment button and select **Production**:

    ![Destinations page showing the environment-selection button](/mulesoft/current/en-us/mq/_images/mq-switch-env.png)

3.  Click **Destinations**:

    ![Destinations page showing the Destinations navigation option and the Add button for creating a new queue](/mulesoft/current/en-us/mq/_images/mq-tutorial-destinations-option.png)

    <table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td><strong>Destinations</strong> navigation menu displays available queues.</td></tr><tr><td><i data-value="2"></i><b>2</b></td><td><strong>Add</strong> icon creates a new queue or exchange.</td></tr></tbody></table>

4.  Click the **Add** icon (![](/mulesoft/current/en-us/mq/_images/icon-blue-plus.png)) to display the menu:

    ![Add icon showing the Queue, Exchange, and FIFO Queue menu options](/mulesoft/current/en-us/mq/_images/mq-tutorial-create-choices.png)

5.  Select **Queue**.

6.  In the **Create Queue** window, enter `myDemoQueue` in the **ID** field:

    ![Create Queue window showing myDemoQueue in the ID field and other default options](/mulesoft/current/en-us/mq/_images/mq-create-queues.png)

    Queue names can contain up to 127 alphanumeric (a-z, A-Z, 0-9) and punctuation (. -) characters.
    They can’t contain spaces or other characters.

7.  If you want, specify any other queue settings.

    For information, see [Create a Queue](https://docs.mulesoft.com/mq/mq-queues#create-a-queue).

8.  Click **Create Queue**.

    Anypoint MQ creates the queue in the **Destinations** page:

    ![Destinations page showing the new queue](/mulesoft/current/en-us/mq/_images/mq-tutorial-queue-details.png)

You have successfully created a queue. Next, you send messages to the queue, verify that the
messages arrived, and view the message payload.

## Step 2. Send Messages to a Queue and Verify That They Arrived

After you create the queue, you test the queue sending messages to it, validating that the messages
arrived in the queue, and retrieving them from the queue.

To send and receive messages from a queue:

1.  In the **Destinations** page, click `myDemoQueue`.

2.  Click **Message Sender** in the navigation menu:

    ![Message Sender page and option in the navigation menu](/mulesoft/current/en-us/mq/_images/mq-tutorial-message-sender-page.png)

3.  Leave the **Type** field set to **Text** and enter `Hello Mules!` in the **Payload** field.

4.  If you want, toggle **Add User Properties**, specify the property name-value pairs to send, and
    click **Add Property**:

    ![Message Sender page showing the Add User Properties toggle](/mulesoft/current/en-us/mq/_images/mq-tutorial-message-sender-user-props.png)

    The **Message Sender** page shows added string properties in blue and number properties in gray.

5.  Click **Send**.

6.  Set the **Type** to **CSV**, enter this in the **Payload** field, and click **Send**:

    ```csv
    "dog",
    "fish",
    "parrot"
    ```

7.  Set the **Type** to **JSON**, enter this in the **Payload** field, and click **Send**:

    ```json
    {
      "animal that walks": "dog",
      "animal that swims": "fish",
      "animal that flies": "parrot"
    }
    ```

    Next, verify that the messages arrived in the queue.

8.  Click **Destinations**.

9.  Click the queue type for `myDemoQueue` to display its details.

    The details pane shows the number of messages in the queue:

    ![Details pane showing three messages in the myDemoQueue queue](/mulesoft/current/en-us/mq/_images/mq-tutorial-msgs-in-queue.png)

10. In the details pane, click the queue details label `myDemoQueue`.

11. Click **Message Browser** in the navigation menu:

    ![Message Browser page and option in the navigation menu](/mulesoft/current/en-us/mq/_images/mq-tutorial-get-messages.png)

12. Enter `5` for the number of messages to retrieve and `10` for the number of seconds to poll.

    You can retrieve between 1-500 messages and poll for between 1-3600 seconds.

13. Click **Get Messages**.

    Anypoint MQ retrieves the messages from the queue and displays them in the Message Browser.

14. Click the message row to view the message payload in the details pane:

    ![Selected message row and details pane showing the payload](/mulesoft/current/en-us/mq/_images/mq-tutorial-msg-browser-payload-details.png)

    <table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td>Selected message</td></tr><tr><td><i data-value="2"></i><b>2</b></td><td>Message payload in the details pane</td></tr></tbody></table>

You have successfully created a queue in Anypoint MQ, sent messages to the queue, verified that the
messages arrived, and viewed the message payload. Next, you create a connected app to connect a Mule
app to Anypoint MQ.

## Step 3. Configure a Connected App

After you test the queue, you configure a connected app, which generates the ID and secret you use
to configure Anypoint MQ Connector.

> [!NOTE] To use connected apps with Anypoint MQ, you must use Anypoint MQ Connector 4.x for Mule 4.
> If you are using Anypoint MQ Connector version 3.x or earlier, configure a client app instead. For
> information, see [Configuring Client Apps](https://docs.mulesoft.com/mq/mq-client-apps).

To create a connected app with Anypoint MQ scopes:

1.  In Anypoint Platform, go to **Access Management**.

2.  Click **Connected Apps** in the navigation pane.

3.  Click **Create app**.

    ![Connected Apps navigation option and Create app button in Access Management](/mulesoft/current/en-us/mq/_images/mq-tutorial-create-connected-apps.png)

    <table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td><strong>Connected Apps</strong> menu option displays and creates connected apps.</td></tr><tr><td><i data-value="2"></i><b>2</b></td><td><strong>Create app</strong> button creates a connected app.</td></tr></tbody></table>

4.  Specify a name, such as `DemoApp1` for the app.

5.  Select **App acts on its own behalf (client credentials)**.

6.  Click **Add Scopes**.

    Scopes are roles with associated permissions, which determine which actions the app can perform
    within an organization and environment. See [Anypoint MQ Scopes](https://docs.mulesoft.com/mq/mq-connected-apps#mq-scopes).

    ![Add Scopes window showing the scopes to add to Anypoint MQ connected apps](/mulesoft/current/en-us/mq/_images/mq-conn-apps-scopes.png)

7.  In **Add Scopes** window:

    1.  Enter "MQ" in the **Filter scopes** field.

    2.  Click **Select all** to select all scopes and click **Next**.

    3.  Select a business group to apply the scopes to and click **Next**.

    4.  Select the **Production** environment and click **Next**.

    5.  Click **Add Scopes**.

8.  Click **Save**.

When you configure the connector in a later step, click **Copy Id** and **Copy Secret** to copy the
ID and secret for `DemoApp1`:

![Connected Apps window showing the Copy Id and Copy Secret buttons](/mulesoft/current/en-us/mq/_images/mq-conn-apps-window.png)

You have successfully configured a connected app. Next, you create a Mule app in Anypoint Studio and
connect it to Anypoint MQ.

## Step 4. Create and Connect a Mule 4.x App to Anypoint MQ in Anypoint Studio 7.x

After you configure the connected app, use Anypoint Studio 7.x to configure an app that connects to
Anypoint MQ. Then, deploy the app to CloudHub, submit a `curl` command to test the connection, and
use Anypoint MQ to view the results.

### Before You Begin

- Install Studio 7.x.

  See [Download and Install Anypoint Studio](https://docs.mulesoft.com/studio/to-download-and-install-studio).

- In Anypoint Platform, change to any environment except Design.

  Ensure that the queue you created in **Anypoint Platform** > **MQ** is also in this environment.

### Configure an App with Anypoint MQ in Anypoint Studio 7.x

First, use Studio 7.x to configure an app that connects to Anypoint MQ:

1.  Start Studio, click **File** > **New** > **Mule Project**, and then name the project `mq-demo`.

2.  Click the **Exchange** icon in the toolbar:

    ![Exchange icon in the Studio 7.x toolbar](/mulesoft/current/en-us/mq/_images/mq-tutorial-studio7-exchange.png)

3.  Enter your Anypoint Platform username and password.

4.  In Exchange, click the **Provided by MuleSoft** navigation menu, select **Connectors** from the
    drop-down menu, and then search for Anypoint MQ Connector:

    ![Exchange window showing the Provided by MuleSoft menu option and Connectors selected, and ](/mulesoft/current/en-us/mq/_images/mq-tutorial-exchange.png)

5.  Select **Anypoint MQ Connector - Mule 4**.

    Studio 7.x supports Mule 4.x.

6.  Click **Add to project**:

    ![Add to project option in Exchange](/mulesoft/current/en-us/mq/_images/mq-tutorial-exchange-add-to-project.png)

7.  At the confirmation prompt, click **Proceed** and then click **OK** in Studio.

8.  In the **Mule Palette** view, click **HTTP**, and then drag the **Listener** to the Studio
    canvas:

    ![HTTP Connector and Listener operations in the Mule Palette](/mulesoft/current/en-us/mq/_images/mq-tutorial-studio7-palette.png)

    <table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td>HTTP Connector displays the Listener operation.</td></tr><tr><td><i data-value="2"></i><b>2</b></td><td>Listener operation identifies the operation to drag to the Mule Palette.</td></tr></tbody></table>

9.  Click **Anypoint MQ** and then drag **Publish** to the **Process** area for the Listener on the
    canvas:

    ![Publish operation in the Studio 7.x canvas](/mulesoft/current/en-us/mq/_images/mq-tutorial-studio7-flow.png)

10. In the canvas, click **Listener**.

11. In the Listener properties window, set **General** > **Path** to `/mq/{messageId}`:

    ![Listener properties window showing the Path field value](/mulesoft/current/en-us/mq/_images/mq-tutorial-studio7-listener-props.png)

12. Click the green plus icon (![](/mulesoft/current/en-us/mq/_images/icon-green-plus.png)) for the **Connector configuration**
    field.

13. In the HTTP Listener **Global Element Properties** window, verify that the value of **Host** is
    `All Interfaces [0.0.0.0]` and **Port** is `8081`, and then click **OK**:

    ![Host and Port settings in the Global Element Properties for the Listener](/mulesoft/current/en-us/mq/_images/mq-tutorial-studio7-listener-config.png)

    The Listener properties window now indicates that there are no errors.

14. In the canvas, click the **Publish** operation.

15. In the Publish properties window, set **Destination** to the [`myDemoQueue`](#create-demo-queue)
    queue that you created earlier in **Anypoint Platform** > **MQ**:

    ![Destination property for the Publish operation in Anypoint Studio](/mulesoft/current/en-us/mq/_images/mq-tutorial-studio7-mq-props.png)

    The location of the queue must be an environment other than Design.

16. Click the green plus icon (![](/mulesoft/current/en-us/mq/_images/icon-green-plus.png)) for the **Connector configuration**
    field to display the **Global Element Properties** window.

17. Return to your **Anypoint Platform** > **MQ** browser window to copy the URL, ID, and secret
    values:

    1.  Click **Destinations**.

    2.  Click **Copy** and select **Connector version 4.x and later** from the menu to copy the URL:

        ![Anypoint MQ Destinations page showing the Copy button and the Connector version dropdown](/mulesoft/current/en-us/mq/_images/mq-tutorial-url.png)

        If you are using Anypoint MQ Connector version 3.x or earlier, configure a client app
        instead. For information, see [Configuring Client Apps](https://docs.mulesoft.com/mq/mq-client-apps).

    3.  In the **Anypoint MQ Config** window in Studio, paste the URL in the **URL** field.

    4.  Return to the [Connected Apps](#connected-apps-window) window and copy the ID and secret for
        the app.

    5.  Paste the ID and secret values to the **Anypoint MQ Config** window in Studio:

        ![Anypoint MQ Config window showing the URL, Client App ID, and Client Secret fields](/mulesoft/current/en-us/mq/_images/mq-tutorial-studio7-mq-config.png)

18. Click **Test Connection** to ensure that the values are correct, and then click **OK** twice.

19. Save your project.

20. In **Package Explorer** in Studio, right-click `mq-demo` and select **Anypoint Platform** >
    **Deploy to CloudHub**.

21. At the prompt, select the environment to which to deploy the app.

22. In the Runtime Manager **Deploying Application** window, click **Deploy Application**:

    ![Deploying Applications page in Runtime Manager showing the Deploy Application button](/mulesoft/current/en-us/mq/_images/mq-tutorial-deploy-app.png)

You have successfully used Studio 7.x to configure an app that connects to Anypoint MQ. Next, you
test the connection by submitting REST API commands to the Anypoint MQ Broker API and using Anypoint
MQ to view the results.

### Test Your Mule 4.x App in Studio 7.x

After you create the app in Studio 7.x, you test your app using a `curl` command to submit a REST
API command to the Anypoint MQ Broker API. Then, use Anypoint MQ to view the results.

To test your app:

1.  In Anypoint Platform, select **Runtime Manager** > **Applications** and ensure that the
    `mq-demo` app is running.

2.  Click the status for the `mq-demo` app to display the details pane.

3.  Copy the **App url** value:

    ![Runtime Manager application details pane showing the App url value](/mulesoft/current/en-us/mq/_images/mq-tutorial-rtm-deploy-url.png)

4.  Run this `curl` command from a command prompt to send the `body` value as an Anypoint MQ
    message.

    Replace _APP-URL_ with the **App url** value that you copied from Runtime Manager.

    ```json
    curl -X POST \
      http://APP-URL/mq/100 \
      -H 'content-type: application/json' \
      -d '[  {
        "body": "Welcome to MuleSoft!"
      }
    ]'
    ```

    The `100` value in the URL is the message ID value as specified by `/mq/{messageId}` in the HTTP
    Listener, which is the identifier for your message.

    If you see a 404 message for `destination not found`, verify that the queue name in the **MQ
    Publish** > **Destination** field in Studio matches the name of the queue in **Anypoint
    Platform** > **MQ**.

    After making changes, redeploy your Mule app to CloudHub by right-clicking the project in Studio
    7.x and selecting **Anypoint Platform** > **Deploy to CloudHub**.

5.  In **Anypoint Platform** > **MQ** > **Destinations**, click the name of the
    [`myDemoQueue`](#create-demo-queue) queue that you created earlier and specified in the
    **Destination** setting for your app in Studio 7.x.

6.  Click **Message Browser** in the navigation menu:

    ![Message Browser page and navigation menu option](/mulesoft/current/en-us/mq/_images/mq-tutorial-get-messages.png)

7.  Enter `5` for the number of messages to retrieve and `10` for the number of seconds to poll.

8.  Click **Get Messages**.

    Anypoint MQ retrieves the messages from the queue and displays them in the Message Browser.

9.  Click the message row to view the message payload in the details pane:

    ![Selected message row and details pane showing the payload](/mulesoft/current/en-us/mq/_images/mq-tutorial-msg-browser-payload-details.png)

    <table><tbody><tr><td><i data-value="1"></i><b>1</b></td><td>Selected message</td></tr><tr><td><i data-value="2"></i><b>2</b></td><td>Message payload in the details pane</td></tr></tbody></table>

10. Try changing the body text in the `curl` command and repeat the steps to view the message.

### Example App XML for Studio 7.x

You can use this XML to create the `mq-demo` app in Studio 7.x.

Click the **Configuration XML** tab in Studio and compare your XML to this example. Make corrections
if necessary.

```xml
<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:anypoint-mq="http://www.mulesoft.org/schema/mule/anypoint-mq" xmlns:http="http://www.mulesoft.org/schema/mule/http"
	xmlns="http://www.mulesoft.org/schema/mule/core"
	xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/anypoint-mq http://www.mulesoft.org/schema/mule/anypoint-mq/current/mule-anypoint-mq.xsd">
	<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="0778dad7-d959-4396-8532-883a6c230501" >
		<http:listener-connection host="0.0.0.0" port="8081" />
	</http:listener-config>
	<anypoint-mq:config name="Anypoint_MQ_Config" doc:name="Anypoint MQ Config" doc:id="973e27ca-beff-4510-88d8-11a05053355b" >
		<anypoint-mq:connection url="https://mq-us-east-1.qax.anypoint.mulesoft.com/api/v1" clientId="CLIENT-ID" clientSecret="CLIENT-SECRET" />
	</anypoint-mq:config>
	<flow name="mq-demoFlow" doc:id="1e7b7e94-0759-4a2f-83f0-f425ca95b571" >
		<http:listener doc:name="Listener" doc:id="57828e3a-d5c0-4b94-ac82-84e2c0e4dd2e" config-ref="HTTP_Listener_config" path="/mq/{messageId}"/>
		<anypoint-mq:publish doc:name="Publish" doc:id="17060fa4-d043-4b2f-bc5b-ecc3c905f5a2" destination="myDemoQueue" config-ref="Anypoint_MQ_Config"/>
	</flow>
</mule>
```

## See Also

- [Create a Queue](https://docs.mulesoft.com/mq/mq-queues#create-a-queue)

- [Anypoint Studio 7.x](https://docs.mulesoft.com/studio/)

- [Anypoint MQ Connector 4.x for Mule 4](https://docs.mulesoft.com/anypoint-mq-connector/latest/)

- [Deploy to CloudHub](https://docs.mulesoft.com/cloudhub/deploying-to-cloudhub)
