The Event-driven integration approved is not new. I have covered the topic before in a previous blog post. This time I will go over the topic again in a new context. Microsoft Azure service bus queue will make the development easier and it is a more reliable platform than many on-premise setups.
The scenario is that you have a survey portal. It wants to push survey data to a Dynamics 365 online instance on a survey submission. In my previous post, I was talking about setup up a webhook handler Web API and a staging database. We can replace both of them with Azure service bus queues.
Like many other software services, an Azure service bus queue takes an input and produces an output. The input is an Azure service bus notification. The output is a listener, and the easier way to implement a listener is to use an Azure Function.
The Azure Function consumption plan is a lot cheaper and the first 1 million requests per month are free. The default timeout of a consumption plan Azure Function is 5 minutes and you can extend it to 10 minutes. The problem is that sometimes an Azure Function will doze into sleep before reaching the timeout and it will not wake up by itself.
Queue VS Topic
The main difference is that the Azure Service Bus Queue can only have one listener whereas the Azure Service Bus Topic can have multiple listeners.
Session enabled Azure Service Bus Queues
Azure Service Bus Queue and Azure Function are a good combination but a session enabled Azure Service Bus Queue cannot trigger an Azure Function! It is a known issue and a frustrating one. Microsoft is currently working on it.
Azure Function Version 2
Azure Function version 2 only support libraries compatible with the .Net standard. It means you cannot use the CrmSdk.XrmTooling.Core library anymore.
The good news is that you don’t need the CrmSdk.XrmTooling.Core library to consume the (relatively) new Dynamics 365 WebAPI endpoints. For authentication, you can use the ADAL.NET library if you code in .NET. You may have better luck with older versions of the library, version 2 or version 3. The HttpClient class represents the communication channel. If you want an extra kick in productivity, I will highly recommend David Yack’s Xrm.Tools.CRMWebAPI library.
Microsoft Azure Service Bus Queue can handle exceptions out of the box by sending failed messages to a dead letter queue.
The classic logging view will sometimes fail to load. Therefore I will highly recommend you to turn on Azure Application Insights. The first 5 GB of Azure Application Insight ingestion per month is free. It is literally free for a small to the medium system. For one system I built, there are 9 Azure Functions and thousands of logs per day and we are not hitting that 5 GB limit.
If for any reason, you just cannot use Azure Application Insight, you can download log files locally to have a look.