How to setup Business Events with Azure Service Bus Queue endpoint in D365FO?

Business events allow you to notify external systems when certain operations in D365FO happens. For example, you can notify an external system when a sales order is invoiced or when a customer electronic address is inserted.

In D365FO, you can manage the destination where you want your business event to be sent to by configuring endpoints. Business events support multiple types of endpoints and in this article we are going to cover the "Azure Service Bus Queue" endpoint where I'm going to show you how to create an azure service bus from scratch and setup it up in D365FO.

In general, "Azure Service Bus" enables applications and systems to communicate with each other and exchange information. And Azure service bus queue is a type that provides a  1-1 communication between the sender and the receiver.

First, let's configure D365FO Business event with Azure service bus queue endpoint:

  1. Go to System Administration - Setup - Business events - Business events Catalog

    Business events catalog

  2. Go to "Endpoints" tab, click "New", choose "Azure service bus queue" endpoint, then click "Next"

    Business events endpoint

  3. Configure the endpoint, by first filling the "Endpoint name" and "Endpoint description" with whatever you like

    Configure business event endpoint

Now to fill the other values, we'll need to do the following:

  • Create azure service bus namespace
  • Create azure service bus queue
  • Create shared access policy for the service bus
  • Create key vault
  • Create a secret
  • Create an app registration
  • Link the app registration with the key vault

Azure service bus namespace
The first step we need to do is to create an azure service bus namespace:

  1. Login to Azure portal https://portal.azure.com
  2. Click on Service bus or search for it

    Service bus

  3. Click on create

    Create service bus

  4. Fill the values below in order to create a service bus namespace, then click "Review + Create" to jump to the "Review + Create" tab.
    • Subscription: Choose your Azure subscription where you would like to create the service bus namespace
    • Resource Group: create a new resource group or use an existing one to link your new namespace to it
    • Namespace name: choose a unique name for your namespace
    • Location: This is where you would like your namespace to be hosted
    • Pricing tier: Choose your pricing tier. Here i chose the pricing tier as "Basic"  because I'm going to create Azure service bus queue but if you are planning to use service bus topics, then you will need to choose pricing tier as "Standard" or "Premium"

    Create Service bus namespace



  5. Click Create

    review and create service bus

  6. Once the deployment is done you can click on go to resource to see your service bus namespace

    Service bus deployment

    Service bus namespace
Azure service bus queue
The next step is to create a service bus queue:
  1. Go to "Entities" in the service bus namespace, then choose "Queues",  click "+ Queue" and start filling details.
    Here i just filled the name and left other values with their defaults

    Create service bus queue

    Service bus queue created

  2. Now you can fill this queue name inside D365FO

    Queue name in business events

Shared access policy
Now let's create a "shared access policy" for the service bus, in order to allow D365FO to send business events to the service bus:
  1. In the service bus name space, click on "Shared access policy" under settings, then click "Add", name your policy and choose "Send" then click "Create".

    Shared access policy

  2. After it gets created, click on it and take note of the "primary connection string" as you will need it later to save it in the key vault secret value.

    Primary connection string

Key Vault
Now let's create a key vault, where you could think of the key vault as a secure place to store keys, secrets and certificates:
  1. Let's go back to Azure portal home page and search for Key Vault

    Key Vaults

  2. Click create

    Create Key Vault

  3. Fill the values as per the image below in order to create a key vault, then click "Next"
    It's somehow similar to how you created the service bus namespace

    Key vault creation

  4. Choose the permission model (here I chose Role based security), then Click "Review + create" to jump to the "Review + create" tab

    Access configuration for key vault

  5. Click Create

    Key Vault Create

  6. Once the deployment is done you can click on go to resource to see your key vault homepage

    Key vault deployment



    Key vault homepage

  7. In your key vault homepage, take note of of the "Vault URI" as this value represents the "Key Vault DNS Name" when setting up the business event

    Key vault URI

    Key vault DNS name


  8. Go to secrets, you might get the RBAC (role-based access control) error as per the image below which will prevent you from generating secrets

    RBAC error
          To solve the error:
    • Go to "Access control (IAM)", click Add, then add role assignment

      Add role assignment for key vault

    • Click on "Key Vault Administrator", then click next

      Key vault administrator

    • Click on "Select members", look for your user and select it, then click "select"

      Select member for role assigment

    • Click Next

      create role assignment

    • Click "Review" + assign

      Review and assign role assigment

  9. After you fix the error in step 7, click "Generate/Import"

    Generate secret

  10. Choose a secret name, and paste the "primary connection string" we took from the "shared access policy" inside the secret value field, then click "Create".
    Take note of the secret name as 
    this value represents the "Key Vault Secret Name" when setting up the business event.

    Key vault secret name
    Key vault secret name in business events

App registration
If you don't have an azure app registration created, then you will need to create a new one. You can check my detailed article on how to create one How to create App Registration in Azure? 
After you create it, you will need to get the "client application Id" and "secret" from the app registration to fill them in the business event configuration.
  1. First you need to make sure that the ClientId is defined in D365FO environment. Go to System Administration - Setup - Azure Active Directory Applications

    Azure active directory application
    • In order to get this clientId, sign in to https://portal.azure.com
    • Go to App registrations and choose your application, where you can find the ClientId

      Client Id

    • In order to get the client secret, click on your app, go to "Certificates & secrets" and take the secret value. Or contact your admin to give you the values

      Client Secret

  2. Now we can fill the the business event setup with those values

    Client application Id and secret

Link app registration with the key vault
  1. The next step is to link the app registration with the key vault, so that the app registration can access the key vault secret
  2. Go to "Access control (IAM)", click Add, then add role assignment
    Add role assignment for key vault

  3. Click on "Key Vault Secrets User", then click next

    Key vault secret user

  4. Click on "Select members", look for the application registration name and select it, then click "select"

    Key vault member

  5. Click Next
    Add role assignment for the application

  6. Click "Review + Assign"

    Review and assign role secret

**Now if you click "ok" in the business event endpoint setup, it will be created successfully.

Setup business events endpoints in D365FO


Business event endpoint is configured successfully


Comments

Popular Posts

How to update D365FO environments to a new Microsoft version?

How to apply database backup from LCS to your D365FO DevBox environment?

How to create a new D365FO cloud-hosted environment?