August 26, 2019

Integrate Dynamics 365 with Azure Service Bus - no code!

Integrate Dynamics 365 with Azure Service Bus - no code!

Do you want to get data from Dynamics 365 or the CDS to an Azure Service Bus without writing any code? Read on my friends.

First, you'll need the following ingredients:

  1. An Azure Subscription
  2. A Dynamics 365 instance
  3. Dynamics 365 CE Plugin Registration Tool
  4. Service Bus Explorer
    5.Pre-heat the oven to 200 degrees C

Now here's an overview of what we're going to do:

  1. Create an Azure Service Bus in the Azure Portal
  2. Create a Queue on the Bus
  3. Create a Shared Access Key (SAS) for writing messages to the Bus
  4. Copy the Connection String
  5. Register a Service EndPoint in Dynamics with the Plugin Registration Tool
  6. Register a Step under the Service EndPoint for the Entity we want to send
  7. Perform a test
  8. Check the results with Service Bus Explorer

Azure Service Bus

1. Create an Azure Service Bus

  • In the Azure Portal, click Create a resource
  • Click Integration, then Service Bus
    azure-portal-create
  • Give it a name, select a subscription, resource group and location
    azure-portal-create-service-bus

2. Create a Queue

  • After the Service Bus has been created, open it (you might need to go back to All Resources for the subscription).
  • On the left-hand navigation for the Service Bus, click Queues
  • Click + Queue
    azure-portal-create-queue-1
  • Provide a name for the queue and leave the other fields as defaults.

3. Create a Shared Access Key (SAS)

  • With the Azure Service Bus pane still open in the Portal, click on the Shared access policies in the left-hand navigation
    azure-portal-sasses
  • Click Add to create a new one.
  • Give it a name - something relevant to D365, and make sure it has Send and Listen checked
    azure-portal-create-sas

4. Copy the Connection String

  • After the SAS has been created above click on it to open the details.
  • Click on the Copy button next to the Primary Connection String. We'll be using this to tell Dynamics 365 where to send messages.
    service-bus-sas-copy-connection-string

Dynamics 365 CE

5. Register Service EndPoint

  • Open the Plugin Registration Tool and connect to your D365 instance (assumed knowledge)
  • Click on Register > Register New Service Endpoint
    register-new-service-endpoint
  • Paste in the Connection String from Step 4
    connection-string
  • At the next dialog, you'll need to set the Queue Name (from Step 2), and change the Message Format to JSON. I recommend you also put in a Description.
    prt-endpoint-registration

6. Register a Step

  • After you've done this, right-click on the Service EndPoint and select Register New Step
    prt-register-new-step
  • At the next dialog this is where we define which Entity, and which Event (message). In my example, I am using the Create event of the account entity. Before you click Save, ensure you change the Execution Mode to Asynchronous. I also recommend you put in a better Step Name and Description than the default.
    prt-create-new-step-dialog

7. Run a Test

  • For this one we simply need to create an Account. This is an exercise left for the reader.

Check the Service Bus

8. Check results

  • Open Service Bus Explorer
    sbe-connect-dialog
  • File > Connect Create a new Connection via Connection String - paste in the Connection String from the default SAS that was created when the Azure Service Bus was created. Note this is different to the value we copied in Step 4 (but you'll find it in the same place).
  • Navigate to the Queue we created
    service-bus-explorer
  • Click on Messages and click OK on the dialog that pops up.
    messages
  • You should now see some Messages in the queue, and the message text. If you copy / paste the message text into Notepad++ or similar, you can see the sweet sweet JSON.

json

Troubleshooting

System Jobs

Did you run a test (Step 7) and nothing appeared in the Service Bus?
If your registration fails for some reason, you can see evidence of this in Settings > System Jobs in Dynamics 365. It will provide you with details of the failure. The first time I tried it, I had pasted in the wrong SAS key and authorization was failing. If the configuration is successful you won't see anything here, it deletes successful jobs.

This post is essentially a combination of the following two Docs: