Learn how to put your digital team to work with MuleSoft for Agentforce.
Contact Us 1-800-596-4880

Azure Service Bus Connector 3.4 Examples - Mule 4

The examples in this section show application flows that:

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

    For more information about using a properties file, see Configuring Property Placeholders

Before You Begin

  • Java 8

  • Anypoint Studio 7.1.0 or later

  • Mule Runtime 4.2.x EE or later

  • Creation of a new queue for testing purpose on Azure Portal

Create a Mule Project

After you create a new Mule project and configure your credentials, you can create an application flow for each example by using the provided XML code.

To create a Mule project:

  1. In Studio, select File > New > Mule Project.

  2. Enter a name for your Mule project and click Finish.

  3. Create a file named mule-app.properties and save it in <project-name>/src/main/resources.

  4. Configure your Azure connection credentials in the file mule-app.properties, and include the name of the Azure queue you created, for example:

    #==============================================================
    #Connection Parameters
    #==============================================================
    # Azure common authentication configuration
    azure.namespace=myazure
    queue.name=mytestqueue
    
    # Shared Access Signature authentication
    azure.keyname=SAStokenname
    azure.key=SAStoken
    
    # Azure Active Directory authentication
    azure.tenantId=TenantId
    azure.clientId=ClientId
    azure.clientSecret=ClientSecret
  5. Save the file.

  6. Open the Global Element Configuration and click Test Connection to verify your credentials.

Send and Receive Example

This flow shows an example of how to use the Send and Receive From Queue operations to send and receive messages:

Example Azure Service Bus flow that uses the Send and Receive From Queue operations

To create this flow:

  1. In the Studio canvas, click Configuration XML.

  2. Delete all the contents after the line <?xml version="1.0" encoding="UTF-8"?>.

  3. Copy and paste the following XML after the line <?xml version="1.0" encoding="UTF-8"?>:

  4. When you are prompted to regenerate doc:id values, click Yes.

  5. Save the project.

  6. Right-click in the Studio canvas and select Run project <project-name> to run the project.

Batch Send and Receive Example

This application flow uses the Send batch and Receive Batch operations to send and receive batches of messages to and from an Azure Service Bus queue.

The following screenshot shows the application flow for sending and receiving batch messages:

Application flow that shows sending and receiving batch messages

To create this flow:

  1. In the Studio canvas, click Configuration XML.

  2. Delete all the contents after the line <?xml version="1.0" encoding="UTF-8"?>.

  3. Copy and paste the following XML after the line <?xml version="1.0" encoding="UTF-8"?>:

  4. Save the project.

  5. Right-click in the Studio canvas and select Run project <project-name> to run the project.

Send, Listen, and Acknowledge the Message Example

This application flow uses the Send and Message Listener operations. The Message Listener is using the MANUAL acknowledgment type, which means that the application logic is responsible for acknowledging receipt of the message. In this example, that logic is provided by adding the Complete operation to the same flow as the Message Listener.

The following screenshot shows this flow:

Application flow that shows how the Send, Message Listener, and Complete operations are used

To create this flow:

  1. In the Studio canvas, click Configuration XML.

  2. Delete all the contents after the line <?xml version="1.0" encoding="UTF-8"?>.

  3. Copy and paste the following XML after the line <?xml version="1.0" encoding="UTF-8"?>:

  4. When you are prompted to regenerate doc:id values, click Yes.

  5. Save the project.

  6. Right-click in the Studio canvas and select Run project <project-name> to run the project.

Using Azure Active Directory Connector Provider

Some organizations use Azure Active Directory to authenticate their instances. Any of the previous examples can be modified to support this scenario. Replace the Shared Access Signature authentication with the Azure Active Directory authentication:

<azure-service-bus-messaging:sas-connection namespace="${azure.namespace}" sharedAccessKeyName="${azure.keyname}" sharedAccessKey="${azure.key}" />
xml
<azure-service-bus-messaging:aad-connection namespace="${azure.namespace}" tenantId="${azure.tenantId}" clientId="${azure.clientId}" clientSecret="${azure.clientSecret}" />
xml

Ensure that:

  • Your mule-app.properties file contains the Tenant Id, Client Id, and Client Secret fields.

  • Your app registration contains the proper permissions and rolesLeaving the Site.

View on GitHub