Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Blogs / Learn with Subs / Strategize integration usin...

Strategize integration using Azure Service Bus with D365F&O and Azure functions

Subhad365 Profile Picture Subhad365 7 User Group Leader

We all know and have worked a lot with Azure Service Bus: queues, topics, and the tattletale around them. Given the rich set of advantages (dead lettering, decoupled applications, load balancers, safety routing: only to name a few)you could get from them, ASBs are really becoming more and more a very powerful Azure component to consume and deal with. The following article explains how you can use ASBs, to make your Azure function listen to them, and then talk to D365F&O: in a most cost effective way.


Step 1: Creating an Azure service bus namespace:

You can create a ASB by simply launching from Azure Portal, and selecting the essential elements which you need, as per your business requirement. 



Enter/select a resource group, give a namespace name. Select: Pricing tier = 'Premium'. Selecting 'Basic' or 'Standard' or enable the Queue option, otherwise. 

Post this, additionally you can check if you need to specify anything explicitly, by clicking on 'Advanced' or else you can directly go for creating the namespace. The namespace would take some moments to deploy.

Your Namespace is now ready to be used.


Step2: create a topic:

In this, we will create a new topic, by creating on the following button from the action pane:



The following popup opens. Fill them up as needed. Don't forget to enable 'auto-delete on idle topic' and as highlighted:


Click 'Create' to complete the step. The step will take a couple of moments to validate the keyed-in values and then will create the topic for you. 

How to view the created Topic?





On the side pane, click on the 'Topics' and you will see the list of all the topics that have been created (selecting a different Pricing tier, other than 'premium' would have just given us 'Queues', and not 'Topics').

Here is our newly created Topic:




Step 3: Create a Subscription
Click on it to view details. Click on +Subscription, to add a new subscription: Give a name = D365FO_Subscription, select 'Enable dead lettering on message expiration' and rest you can leave with default values. Click 'Create' to finish the step. This will create the Subscription and you can view it at as follows:




Click on it to view the details. Here we will create the 'Correlation' filter and this is the most interesting part of the entire story.
Step4: Creating a filter
In the following screen, click on 'Add filter':


From the following screen, select 'Correlation filter'. Select 'Label' from the dropdown and give a suitable identifier label to your message:


Click to save changes.
Like this you can create as many message label filters as possible. The idea is to 'filter' only the customer records/vendor records/pools records as per recipient's wish: not to cross listen to any unwanted data.





How this works


Reach out to Topics\D365FO >>Service bus explorer >> select a subscription >> D365FO_Subscription:


You can Send a message from here >> click on "Send Messages" >> the following popup opens:



Select content-type: application/JSON. Go to the bottom >> expand: Broker properties, to set the label of desired value:

Which enables it to be used as a SalesPool type of message. Click Send. Come back to your Service bus explorer, select 'Receive message' from 'Peek mode' drop down:
Uploading: 25695 of 25695 bytes uploaded.
Click on 'Receive message' >> it will download only the intended labelled message (in our case SalesPool). In case of any other labelled message is there, it will simply filter out:




Additionally, as you turned on Dead-lettering, it will expire the message if unattended after a given time, and also you can peek messages from the start ( receiving the message means it will read the message just once for you, you might not be able re-read again. Peeking can let you read any message, starting from the start).

Ok, all set?
Let us now explore how to consume the message received from Service bus to D365FO, using Azure Functions. 
Step 1: Creating the Azure function
In your Visual Studio (alternately you can also use Visual Studio Code) >> create new project >> in the template search for  Azure function, the following screen appears:
Select Function = Service Bus Topic Trigger.
Here Topic name is = is the name of my topic which I created in my service bus, subscription name is the name of my subscription which I created.

  
In the Connection String property, just write: sbConStr for now. Will explain what's this in the next point.
Click create to continue.

Step 2: Getting the connection string
To get the connection string, go to Azure Functions >> Shared Access Policies:





 Click on the same. The following screen opens:




Copy the 'Connection string' value by clicking on the highlighted icon. Come back to VS >> Go to LocalSettings.JSON >> Create a new entry called 'sbConStr' as below:

Consequently your code now looks like this:

Consequently when I am sending the following message in my Service bus explorer, 
with the label = SalesPool:


It lands successfully in D365FO as:

The console of your VS registers the message you have posted as:


So much for today. See you soon with a new idea. Keep daxing, keep Azuring.

 

Comments

*This post is locked for comments