Azure Service Bus Management 1.0 Examples | MuleSoft Documentation
# Azure Service Bus Management 1.0 Examples
The examples in this section show how to get information about Azure Service Bus queues and how to create an Azure Service Bus topic. These examples use variables for some field values. You can either:
  * Replace the variables with their values in the code
  * Provide the values for each variable in a properties file and then refer to that file from the connector configuration
If you don’t know how to use a properties file, see Configuring Property Placeholders


## Before You Begin
Ensure you have the following:
  * Java 8, 11, or 17
  * Anypoint Studio 7.5 and later
  * Mule runtime engine (Mule) 4.3.0 and later
  * DataWeave


## Get Queue Information Example
This example shows how to get information about a particular queue in the Azure service bus instance. The following screenshot shows the Anypoint Studio app flow for this example:
Figure 1. App flow for the Get Queue Information example
  1. Create a new Mule project in Studio.
  2. In the **Mule Palette** view, search for `http` and select the **Listener** operation:
  3. Drag the **Listener** operation onto the Studio canvas.
  4. In the **Listener** configuration, click **+** next to the **Connector configuration** field to add a global element.
  5. Accept the defaults.
  6. Set the **Path** field to `/queue`.


### Add and Configure the Get Entity Operation Example
Add the **Get Entity** operation to see information about the specified queue, including configuration information and information about the metadata:
  1. In the **Mule Palette** view, search for `azure` and select the Azure Service Bus Management Connector **Get Entity** operation.
  2. Drag the **Get Entity** operation onto the Studio canvas, to the right of **Listener**.
  3. In the **Get Entity** configuration, click **+** next to the **Connector configuration** field to add a global element.
  4. Enter values for the **SMS Namespace** , **Shared Access Key Name** , and **Shared Access Key** fields.
  5. Click **Test Connection** to confirm that Mule can connect with the Azure Service Bus instance:
     * If the connection is successful, click **OK** to save the configuration.
     * Otherwise, review to correct any incorrect parameters, and test again.
  6. In the **Entity(Queue or Topic)** field, enter the name of the queue for which you want information.


### Add a Transform Message Component
Add a **Transform Message** component to format the data and show how the metadata is rendered for the output of the **Get Entity** operation:
  1. In the **Mule Palette** view, search for `transform`:
  2. Drag the **Transform Message** component onto the canvas, to the right of the **Get Entity** component.
  3. In the **Transform Message** configuration, change the display name to `Getting Data`.
  4. Overlay the brackets in the **Output** section with this XML:
```
%dw 2.0
output application/json
ns ns0 http://www.w3.org/2005/Atom
ns ns01 http://schemas.microsoft.com/netservices/2010/10/servicebus/connect
---
{
"title": payload.ns0#entry.ns0#title,
"publishedAt": payload.ns0#entry.ns0#published,
"lockDuration": payload.ns0#entry.ns0#content.ns01#QueueDescription.ns01#LockDuration,
"maxSize": payload.ns0#entry.ns0#content.ns01#QueueDescription.ns01#MaxSizeInMegabytes,
"requiresDuplicate": payload.ns0#entry.ns0#content.ns01#QueueDescription.ns01#RequiresDuplicateDetection,
"requiresSession": payload.ns0#entry.ns0#content.ns01#QueueDescription.ns01#RequiresSession,
"deadLettering": payload.ns0#entry.ns0#content.ns01#QueueDescription.ns01#DeadLetteringOnMessageExpiration,
"enabledBatched": payload.ns0#entry.ns0#content.ns01#QueueDescription.ns01#EnableBatchedOperations,
"defaultMTTL": payload.ns0#entry.ns0#content.ns01#QueueDescription.ns01#DefaultMessageTimeToLive,
"duplicateDetection": payload.ns0#entry.ns0#content.ns01#QueueDescription.ns01#DuplicateDetectionHistoryTimeWindow,
}
```



### Add a Logger Component
Add a Logger component to show the response in the **Mule Console** :
  1. In the **Mule Palette** view, search for `logger` and select the **Logger (Core)** component.
  2. Drag the **Logger (Core)** component onto the Studio canvas, to the right of the **Transform Message** component.
  3. In the **Message** field of the Logger configuration, enter `#[payload]`.
  4. Save the project.
  5. Test the app by sending a GET request to `http://127.0.0.1:8081/queue`.


### XML Code for the Get Queue Example
```
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:azure-service-bus-management="http://www.mulesoft.org/schema/mule/azure-service-bus-management"
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/azure-service-bus-management http://www.mulesoft.org/schema/mule/azure-service-bus-management/current/mule-azure-service-bus-management.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/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<azure-service-bus-management:config name="Azure_Service_Bus_Management_Connector_Config" doc:name="Azure Service Bus Management Connector Config" >
<azure-service-bus-management:shared-access-signature-connection namespace="azure-management-testing" sharedAccessKeyName="RootManageSharedAccessKey" sharedAccessKey="FgBRI++kphTGJcr2OL8G3BLLAdAn3p7newgQ2Ixf7hk="/>
</azure-service-bus-management:config>
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" >
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<flow name="azure-management-flow" >
<http:listener doc:name="Listener" config-ref="HTTP_Listener_config" path="queue"/>
<azure-service-bus-management:get-by-entity doc:name="Get Entity" config-ref="Azure_Service_Bus_Management_Connector_Config" entity="your-queue"/>
<ee:transform doc:name="Getting data" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
ns ns0 http://www.w3.org/2005/Atom
ns ns01 http://schemas.microsoft.com/netservices/2010/10/servicebus/connect
---
{
"title": payload.ns0#entry.ns0#title,
"publishedAt": payload.ns0#entry.ns0#published,
"lockDuration": payload.ns0#entry.ns0#content.ns01#QueueDescription.ns01#LockDuration,
"maxSize": payload.ns0#entry.ns0#content.ns01#QueueDescription.ns01#MaxSizeInMegabytes,
"requiresDuplicate": payload.ns0#entry.ns0#content.ns01#QueueDescription.ns01#RequiresDuplicateDetection,
"requiresSession": payload.ns0#entry.ns0#content.ns01#QueueDescription.ns01#RequiresSession,
"deadLettering": payload.ns0#entry.ns0#content.ns01#QueueDescription.ns01#DeadLetteringOnMessageExpiration,
"enabledBatched": payload.ns0#entry.ns0#content.ns01#QueueDescription.ns01#EnableBatchedOperations,
"defaultMTTL": payload.ns0#entry.ns0#content.ns01#QueueDescription.ns01#DefaultMessageTimeToLive,
"duplicateDetection": payload.ns0#entry.ns0#content.ns01#QueueDescription.ns01#DuplicateDetectionHistoryTimeWindow,
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Logger" message="#[payload]"/>
</flow>
</mule>
```
## Create Topic Example
This example shows how to create a new topic for the Azure Service Bus instance. The following screenshot shows the Anypoint Studio flow for this example:
Figure 2. App flow for the Create Topic example
  1. Create a new Mule project in Studio.
  2. In the **Mule Palette** view, search for `http` and select the **Listener** operation:
  3. Drag the **Listener** operation onto the canvas.
  4. In the **Listener** configuration, click **+** next to the **Connector configuration** field to add a global element.
  5. Set the **Host** field to 0.0.0.0, the **Port** field to `808`, and click **Save**.
  6. Set the **Path** field to `/topic`.


### Add and Configure the Create or Update Entity Operation
The **Create or Update Entity** operation enables you to create the topic:
  1. In the **Mule Palette** view, search for `azure service bus management` and select the **Create or Update Entity** operation.
  2. Drag the **Create or Update Entity** operation onto the canvas, to the right of **Listener**.
  3. In the **Create or Update Entity** configuration, click **+** next to the **Connector configuration** field to add a global element.
  4. Enter values for the **SMS Namespace** , **Shared Access Key Name** , and **Shared Access Key** fields.
  5. Click **Test Connection** to confirm that Mule can connect with the Azure Service Bus instance:
     * If the connection is successful, click **OK** to save the configuration.
     * Otherwise, review or correct any incorrect parameters, and test again.
  6. In the **Entity(Queue or Topic)** field, enter the name of the queue for which you want information.


### Add a Transform Message Component
Add a **Transform Message** component to format the data and show how the metadata is rendered for the output of the **Create or Update Entity** operation:
  1. In the **Mule Palette** view, search for `transform`:
  2. Drag the **Transform Message** component onto the canvas, to the right of the **Create or Update Entity** component.
  3. In the **Transform Message** configuration, change the display name to `Getting Data`.
  4. Overlay the brackets in the **Output** section with this XML:
```
%dw 2.0
output application/json
ns ns0 http://www.w3.org/2005/Atom
ns ns01 http://schemas.microsoft.com/netservices/2010/10/servicebus/connect
---
{
title: payload.ns0#entry.ns0#title,
publishedAt: payload.ns0#entry.ns0#published,
maxSize: payload.ns0#entry.ns0#content.ns01#TopicDescription.ns01#MaxSizeInMegabytes,
requiresDuplicate: payload.ns0#entry.ns0#content.ns01#TopicDescription.ns01#RequiresDuplicateDetection,
enableBatched: payload.ns0#entry.ns0#content.ns01#TopicDescription.ns01#EnableBatchedOperations,
defaultMTTL: payload.ns0#entry.ns0#content.ns01#TopicDescription.ns01#DefaultMessageTimeToLive,
duplicateDetection: payload.ns0#entry.ns0#content.ns01#TopicDescription.ns01#DuplicateDetectionHistoryTimeWindow,
}
```



### Add a Logger Component
The Logger component displays the new topic in the **Mule Console** :
  1. In the **Mule Palette** view, search for `logger` and select the **Logger (Core)** component.
  2. Drag the **Logger (Core)** component onto the Studio canvas, to the right of the **Transform Message** component.
  3. In the **Message** field of the Logger configuration, enter `#[payload]`.
  4. Save the project.
  5. Test the app by sending a GET request to `http://127.0.0.1:8081/topic`.


### XML for the Create Topic Example
```
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:azure-service-bus-management="http://www.mulesoft.org/schema/mule/azure-service-bus-management"
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/azure-service-bus-management http://www.mulesoft.org/schema/mule/azure-service-bus-management/current/mule-azure-service-bus-management.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/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
<azure-service-bus-management:config name="Azure_Service_Bus_Management_Connector_Config" doc:name="Azure Service Bus Management Connector Config" doc:id="a59bdeee-75d3-4708-b3e1-923189366fcf" >
<azure-service-bus-management:shared-access-signature-connection namespace="azure-management-
ing" sharedAccessKeyName="RootManageSharedAccessKey" sharedAccessKey="FgBRI++kphTGJcr2OL8G3BLLAdAn3p7newgQ2Ixf7hk="/>
</azure-service-bus-management:config>
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="d3ad3e78-e927-47fd-9aa9-997c5d3cb5ff" >
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<flow name="azure-management-flow" doc:id="2ca28772-b9ce-44ec-a0d3-68568789cb8e" >
<http:listener doc:name="Listener" doc:id="60a97736-63e4-42bb-8487-e656cad985d6" config-ref="HTTP_Listener_config" path="topic"/>
<azure-service-bus-management:update-by-entity doc:name="Create or Update Entity" doc:id="b7bda909-831f-4e05-b4da-810adb8b541d" config-ref="Azure_Service_Bus_Management_Connector_Config" entity="topicName">
<azure-service-bus-management:content ><![CDATA[#['<?xml version="1.0" encoding="UTF-8"?>
<entry xmlns="http://www.w3.org/2005/Atom">
<content type="application/xml">
<TopicDescription xmlns="http://schemas.microsoft.com/netservices/2010/10/servicebus/connect">
<MaxSizeInMegabytes>1024</MaxSizeInMegabytes>
<RequiresDuplicateDetection>false</RequiresDuplicateDetection>
<EnableBatchedOperations>false</EnableBatchedOperations>
<DefaultMessageTimeToLive>PT256204778H48M5S</DefaultMessageTimeToLive>
<DuplicateDetectionHistoryTimeWindow>PT10M</DuplicateDetectionHistoryTimeWindow>
</TopicDescription>
</content>
</entry>']]]></azure-service-bus-management:content>
</azure-service-bus-management:update-by-entity>
<ee:transform doc:name="Getting data" doc:id="67b79a1a-2eec-4ed5-a160-c44b14da829b" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
ns ns0 http://www.w3.org/2005/Atom
ns ns01 http://schemas.microsoft.com/netservices/2010/10/servicebus/connect
---
{
title: payload.ns0#entry.ns0#title,
publishedAt: payload.ns0#entry.ns0#published,
maxSize: payload.ns0#entry.ns0#content.ns01#TopicDescription.ns01#MaxSizeInMegabytes,
requiresDuplicate: payload.ns0#entry.ns0#content.ns01#TopicDescription.ns01#RequiresDuplicateDetection,
enableBatched: payload.ns0#entry.ns0#content.ns01#TopicDescription.ns01#EnableBatchedOperations,
defaultMTTL: payload.ns0#entry.ns0#content.ns01#TopicDescription.ns01#DefaultMessageTimeToLive,
duplicateDetection: payload.ns0#entry.ns0#content.ns01#TopicDescription.ns01#DuplicateDetectionHistoryTimeWindow,
}]]></ee:set-payload>
</ee:message>
</ee:transform>
<logger level="INFO" doc:name="Logger" doc:id="577d2989-1b0b-4c95-a16b-3cce4b4ccaca" message="#[payload]"/>
</flow>
</mule>
```

## See Also
  * Introduction to Anypoint Connectors
  * MuleSoft Help Center