Monday, June 27, 2016

CRM and Azure Service Bus Integration Part 3

This is the third part of the series. Please check the last blog first, if you haven’t already.In this blog we go through a step by step tutorial to setup a CRM-Azure integration using service bus queue via SAS(Share Access Signature).

Prerequisite

  • A CRM Online instance
  • Microsoft Azure account
  • Microsoft Azure SDK
  • Visual Studio 2013/2015
  • CRM2016 SDK V8.1 or later ( We will be using the plugin registration tool and sample code from the SDK 8.1 as the SAS featured is added to CRM2016 Update 1)

Setting up a Service Bus Namespace and Queue

For this post we will using the same Service Bus namespace we have created in the last post http://mscrmshop.blogspot.com.au/2016/06/crm-and-azure-service-bus-integration_20.html. We will add a new queue to the existing Service Bus namespace.
  1. Login to Azure Portal.
  2. Select the Service Bus namespace. Click the “Queues” tab and select “Create A New Queue”

    2016-06-22_14-28-05
  3. Enter the values as shown in the following screenshot and click “Create A New Queue”
    2016-06-22_14-30-18
  4. A new queue will be created as shown in the screenshot.
    2016-06-22_14-30-58
  5. Double click on the queue name and select “Configure”. Change the general settings as required. I am using the default settings. Create a new policy to mange the access to the queue.
    2016-06-27_13-40-12

    2016-06-27_13-44-54
  6. Click on “DASHBOARD” and select “View Connection String” as shown in the screenshot.
    2016-06-27_13-51-04
  7. It will display the "access connection information" as shown in the following screenshot. Copy the connection string. It will be used in the next step.

    2016-06-27_13-53-43

Setting up the CRM Service Endpoint

Here are the steps
  1. Start the plugin registration tool. It is available in the \SDK\Tools location of the SDK. I am using SDK v8.1
  2. Click on Register>>Register New Service Endpoint
    2016-06-28_10-45-05 
  3. It will prompt for the connection string. Paste the connection string for the queue here and click “Next”
    2016-06-27_13-59-12
  4. The registration tool will display the following page. It will prefill most of the values. I have updated the message format to JSON for this post. Click “Save” to save the service endpoint.
    2016-06-27_14-08-15
  5. Select the service endpoint and select "Register New Step", as shown in the screenshot.
    2016-06-28_10-48-23
  6. For this blog post I am using create message on account entity. You can chooses the other messages and entities as required. Click “Register New Step” to complete the registration.
    2016-06-22_14-37-09

Test the Integration

Queue integration does not require an active listener. So just create a new account from the front end. It should post a message to the queue. You can check status of the integration in the CRM system jobs. view.
Also, you can login to azure. Navigate to the queue and check the queue length. This column displays the number messages received by the queue.
2016-06-22_14-44-17

Reading from the queue

Microsoft has provided the Azure sample. For this post, I am using the Azure sample code that comes with the CRM SDK. Here are the steps
  1. Open the “PersistentQueueListener” project from the location  \SDK\SampleCode\CS\Azure\PersistentQueueListener.
  2. Resolve the missing reference as done in the last blog post (http://mscrmshop.blogspot.com.au/2016/06/crm-and-azure-service-bus-integration_20.html)
  3. Run the code. Provide the values for service namespace, issuer name and issuer secret.The code will read the message from the queue and display its contents.
    Note: The CRM sample code is using the ACS issuer name and issuer secret to generate SAS token. So please provide the ACS values as explained in the last blog.
    2016-06-22_14-59-06

1 comment: