Connecting to Azure Service Bus

This section describes how to configure WSO2 Micro Integrator to connect with Azure Service Bus. Azure Service Bus is a messaging service that exists on Azure Cloud. It only needs to be configured in order to work.

The Azure Service Bus complies with both AMQP 1.0 and JMS 2.0. The Micro Integrator uses its inbuilt JMS transport to send and receive messages from the Azure Service Bus. The configurations are similar to connecting with other JMS brokers.

Setting up the Micro Integrator with Azure Service Bus

Follow the instructions below to set up and configure Micro Integrator to work with Azure Service Bus.

  • To get started, download and install WSO2 Micro Integrator.

Setting up Azure Service Bus

To set this up, configure a queue in Azure Service Bus to work with the synapse configuration.

Service Bus queues can be used to communicate between various on-premise and cloud applications and components. Using queues enables you to scale your applications more easily, and enable more resiliency to your architecture.

For more information on creating a queue, see the Azure Service Bus documentation.

Following the above Azure Service Bus documentation to do the following.

  1. Create an Azure Service Bus named my-mq by selecting a pricing tier of your choice.

  2. Create a queue named integration-queue. Navigate to that by going to Home > my-mq | Queues

  3. Add a shared access policy named my-mq-policy assigning Send and Listen. Go to Home > my-mq | Queues > integration-queue (my-mq/integration-queue) | Shared access policies.

    Note

    The primary key will be generated by the system. Please note that if the primary key has + sign, then you have to delete and create the policy again with the same name until you get a primary key without the + sign. This is done to avoid issues in the library used to connect with the Azure Service Bus that does not working correctly when the primary key has the + sign.

  4. The Maximum Delivery Count property is set to 5 because it reduces the testing time. The default value is 10. Navigate to Home > my-mq | Queues > integration-queue (my-mq/integration-queue) | Properties to configure this.

Now the WSO2 enterprise integrator should be configured to work with Azure Service Bus.

Setting up the Micro Integrator to work with Azure Service Bus

The messaging flow is as shown below.

To set up the messaging flow in WSO2 Integration Studio, create synapse artifacts to create a consumer and a producer.

Azure Service Bus Producer

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="AzureServiceBusProducer" startOnLoad="true" statistics="disable" trace="disable" transports="http,https">
   <target>
      <inSequence>
         <log>
            <property name="in" value="==== IN =====" />
         </log>
         <property action="remove" name="TRANSPORT_HEADERS" scope="axis2" />
         <property name="OUT_ONLY" scope="default" type="STRING" value="true" />
         <call blocking="true">
            <endpoint>
               <address uri="jms://integration-queue?transport.jms.ConnectionFactory=azureQueueProducerConnectionFactory&amp;transport.jms.Destination=integration-queue" />
            </endpoint>
         </call>
         <payloadFactory media-type="json">
            <format>
            {"status":"successful"}
            </format>
            <args />
         </payloadFactory>
         <property name="HTTP_SC" scope="axis2" type="STRING" value="200" />
         <respond />
      </inSequence>
      <outSequence />
      <faultSequence>
         <property name="SET_ROLLBACK_ONLY" value="true" scope="axis2" />
         <payloadFactory media-type="json">
            <format>
            {"status":"failed"}
            </format>
            <args />
         </payloadFactory>
         <property name="HTTP_SC" scope="axis2" type="STRING" value="500" />
         <respond />
      </faultSequence>
   </target>
   <description />
</proxy>

Azure Service Bus Consumer

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse" name="AzureServiceBusConsumer" startOnLoad="true">
   <description />
   <target>
      <inSequence>
         <call blocking="true">
            <endpoint>
               <http uri-template="http://localhost:8280/data/glossary"/>
             </endpoint>
         </call>
         <log level="custom">
            <property name="Transaction Action" value="Committed"/>
         </log>
      </inSequence>
      <outSequence />
      <faultSequence>
         <property name="SET_ROLLBACK_ONLY" value="true" scope="axis2"/>
         <log level="custom">
            <property name="Transaction Action" value="Rollbacked"/>
         </log>
      </faultSequence>
   </target>
   <parameter name="transport.jms.DestinationType">queue</parameter>
   <parameter name="transport.jms.Destination">integration-queue</parameter>
   <parameter name="transport.jms.ContentType">
      <rules xmlns="">
         <jmsProperty>contentType</jmsProperty>
         <default>text/plain</default>
      </rules>
   </parameter>
   <parameter name="transport.jms.ConnectionFactory">azureQueueConsumerConnectionFactory</parameter>
</proxy>

Sample API

<?xml version="1.0" encoding="UTF-8"?>
<api context="/data" name="SampleAPI" xmlns="http://ws.apache.org/ns/synapse">
   <resource methods="POST" url-mapping="/glossary">
      <inSequence>
         <log level="custom">
            <property name="REQUEST" expression="json-eval($.)" />
         </log>
         <payloadFactory media-type="json">
            <format>
            {"status":"successful"}
            </format>
            <args />
         </payloadFactory>
         <property name="HTTP_SC" scope="axis2" type="STRING" value="200" />
         <respond />         
      </inSequence>
      <outSequence/>
      <faultSequence/>
   </resource>
</api>

Do the following to set this up.

  1. Copy the following external .jar files to the MI_HOME/lib directory.

  2. If you want the Micro Integrator to receive messages from an Azure Service Bus instance, or to send messages to an Azure Service Bus instance, you need to update the deployment.toml file with the relevant connection parameters.

    • Add the following configurations to enable the JMS listener with Azure Service Bus connection parameters.

      [[transport.jms.listener]]
      name = "azureQueueConsumerConnectionFactory"
      parameter.initial_naming_factory = "org.apache.qpid.jms.jndi.JmsInitialContextFactory"
      parameter.provider_url = "conf/jndi.properties"
      parameter.connection_factory_name = "SBCF"
      parameter.connection_factory_type = "queue"
    • Add the following configurations to enable the JMS sender with Azure Service Bus connection parameters.

      [[transport.jms.sender]]
      name = "azureQueueProducerConnectionFactory"
      parameter.initial_naming_factory = "org.apache.qpid.jms.jndi.JmsInitialContextFactory"
      parameter.provider_url = "conf/jndi.properties"
      parameter.connection_factory_name = "SBCF"
      parameter.connection_factory_type = "queue"
      3. Start the Micro Integrator.

Now you have configured instances of Azure Service Bus and WSO2 Micro Integrator.

Top