Sunday, January 08, 2017

Using Azure Service Bus and Dynamics 365

You can connect CRM Online (Dynamics 365) with Azure Service Bus by coupling the CRM event execution pipeline to the Microsoft Azure Service Bus. This connection lets the data that has been processed as part of the current CRM operation to be posted to the bus. From here, other line of business applications can consume these messages from Service Bus instead of directly talking with CRM. This is a commonly used hybrid integration scenario.

As of CRM Online Update 1 (Spring release – see KB 2925359 Microsoft Dynamics CRM Online releases for an overview of the different release) – the recommended way of integrating Dynamics CRM Online and Azure Service Bus is using Shared Access Signature authentication.This blog post still uses ACS(Access Control Service) authentication – in a next post I will outline the differences when using SAS (Shared Access Signature) authentication.

Dynamics CRM Online is by default pre-configured for Microsoft Azure integration. You will however still need to proceed with the following steps:
  1. Make sure that you have the Microsoft Azure PowerShell module installed – if you have multiple subscriptions linked to your login – check out  Quick tip – using Azure PowerShell with multiple subscriptions
  2. Create a Service Bus Namespace as outlined in Walkthrough: Configure Microsoft Azure ACS for integration with Dynamics CRM (https://msdn.microsoft.com/en-us/library/jj863635.aspx )
  3. Add extra configuration settings on Azure Service Bus :
    1. Create a service identity (issuer)
    2. Create a rule group and rules
    3. Configure the scope
  4. These settings can be configured in two different ways
    1. Follow the steps outlined in
    2. Use the plugin registration tool to add the extra required configuration using the (Save & Configure ACS) screen when you register a new endpoint. I will use this option since this is the simplest from a developer perspective – before you can use this screen make sure that you perform the next two steps. First you will need to download the certificate from Dynamics CRM Online – it can be found underneath Settings>Customizations>Developer resources screen
      Next you will need to open Azure Portal (I will be using the classic portal https://manage.windowsazure.com since Azure Service Bus management is still in preview on the new portal) and select the connection information from the Azure Service Bus namespace that you created in the first step. Copy the default key. 
You have now completed all the preparation, so now you can proceed with the configuration within CRM. You will need to create a service endpoint configuration in CRM to allow it to talk to Azure Service Bus. A endpoint is a commonly used term in enterprise integration patterns – (See Introduction to messaging endpoints -  for more details). Endpoints in CRM are used to connect CRM to a messaging system so that it can send and receive messages. As already mentioned, CRM provides standard functionality to integrate with Azure Service Bus as a messaging system.

In this example we are going to integrate CRM with a persistent queue and we are going to leverage the built-in Azure plugin in Dynamics CRM. Open the plugin registration tool and select Register New Service EndPoint.


You should see the screen below for registering a new service endpoint – if you get another screen you are most likely using a newer version of the CRM SDK – and you switch to the CRM 2015 SDK or the first build of the CRM 2016 SDK (December 2015 release). 



Before Dynamics CRM Online can post on the queue you will need to create the queue which was specified in the path “jopx/demo”. You can write code for this or you can simply use a tool such Service Bus Explorer - https://code.msdn.microsoft.com/windowsapps/Service-Bus-Explorer-f2abca5a to create the queue (or you can create the queue from within the Azure Management Portal)
Click on Save & Configure ACS to add the necessary configuration data as outlined before. Here you will need to enter the following information:
  • Fill in the management key that you copied over from the Azure Service Bus connection information
  • Select the certificate file that you downloaded from your CRM Online instance
  • Fill in the issuer name – crm4.dynamics.com (This information is also copied over from the Developer resources screen in Dynamics CRM)
When you click Configure ACS – information will be logged on the same screen make sure that you don’t get any errors.


Finally, you will need to define for which CRM entity you want to couple the event execution pipeline to the Microsoft Azure Service Bus. The native CRM Azure-aware plugin allows you to post the data that is being processed as part of the current CRM operation to the queue. It does this by transferring the information in the form of a serializable RemoteExecutionContext object. Registering the Azure-aware plugin is the same as registering any plugin for CRM. Use the plug-in registration tool and right-click on the service endpoint that you just created, then select Register New step to select the “Create” message and the “Contact” entity.


To test it out you simply create a new contact record and you should see that a new entry appears in the CRM System Jobs. After creating a new contact you should have an entry in the CRM System Jobs:  Settings > System Jobs,  indicating that the asynchronous plugin posting the create to Azure has been executed. You can also see the message posted on the queue in the Azure Portal.


2 comments:

Allan Walker said...
This comment has been removed by a blog administrator.
Allan Walker said...

Do you know if the Azure-aware plugin has any transient fault handling built in? For example, if the plugin is unable to send the message context to the Azure Queue, will it attempt any retries or simply fail?