This is going to be a several part series where we will see how we can harness the power of Cosmos DB with Microsoft Dynamics 365. We will take a sample scenario of a multinational transportation network company offering services that include peer-to-peer ridesharing, food delivery, etc. like Uber, let’s name it ‘Troopers’ (well, I’m a star wars fan after all).
We will use Cosmos DB in order to store the CRM data’s in Cosmos DB and sync the data with all other external DB systems. The purpose of implementation is to use the Cosmos DB as a centralized database system.
Steps that involved in integrating D365 with Cosmos DB
- Create Service Bus in Azure portal.
- Create Cosmos DB and Collections in Azure portal.
- Create Function App to perform the necessary business logic.
- Configure the service bus connection using the plugin registration tool.
We will need the following resources to accomplish this integration.
- Microsoft Dynamics 365 (online)
- Azure Cosmos DB collections (Document DB)
- Azure Service Bus Queue
- Azure Function App with Services Bus Queue trigger
- Azure Function App with Cosmos DB trigger (Will see this in separate sessions)
Before we start the brief note of this integration we will have a small introduction about the Cosmos DB and why we chose the Cosmos DB to implement in our example when we have several numbers of Database avail in the market.
Azure Cosmos DB collections (Document DB)
AKA Azure Document DB – Cosmos DB is known Azure Document DB as the earlier, it’s one of the non-relational databases with a cloud-based system.
Globally distributed – The database service is globally distributed; it allows to manage your data’s even if stored it in data centres that are scattered throughout the world.
High tenancy – used to read and write the data’s in a fast manner. It’s kind of non-structured database that store the values in JSON format. Unlike our traditional database, we don’t need to specify the data types and data structure.
API to access Cosmos DB:
Cosmos DB generally provides the APIs for access the data models. Here the following APIs provided by Microsoft based on the language:
- SQL API
- MongoDB API
- Cassandra API
- Graph (Gremlin) API
- Table API
For our integration, we will be using SQL API as it is familiar with most of us.
Why Azure Cosmos DB?
The traditional database system takes a long time and lots of efforts to build a similar global distributed data system. And also have to maintain it in your data centres and it takes in place of huge cost to maintain the resources. So that companies think it wouldn’t be worth investing it on more.
The situation has changed when cloud computing and Platform-as-a-service (Paas) came along and provides the high scalable distributed Database for your company. So it’s so easy to architect and manage your distributed DB systems.
Azure Cosmos DB is Microsoft’s globally distributed, multi-model database service. With a click of a button, Cosmos DB enables you to elastically and independently scale throughput and storage across any number of Azure regions worldwide.
These are the few points that we would prefer Azure Cosmos DB:
- Complete service and ready to use: It gives you a complete product that is powered by Azure and can be automatically replicated in data centres worldwide.
- A number of consistency levels: It uses five different consistency levels: bounded staleness, strong, session, eventual, and consistent-prefix.
- Latency: Very low latency is practically guaranteed at less than 10 milliseconds when reading data and less than 15 milliseconds when writing data.
Steps to create the Service Bus Queue
In order to connect the D365 CE (CRM) system with function app, we use the azure service bus queue and it will post the CRM messages in function app to perform the business logic
- Log in with Azure portal and create the Service Bus queue with respective service bus namespace and create the new service bus queue. (On click of the New button it will ask for some additional optional like Message time to live, Lock duration Enable sessions, etc.) Leave it as default value as shown we will see the options detail in later sessions.
- Once the service bus queue has been created it will be list outed in the queue list. Open the newly created Queue to get the connection string to establish the connection between CRM and azure service bus. From the left side navigation, you can find the option called share access policy.
- On click of the shared access policies, you will be redirected to the policy page. If you have any existing policies, you choose that or click on the create new policy button. Policy is nothing is shows the privilege on the services bus either only to send the message or listen or managed (both send and listen).
- After successful creation of custom policy to services bus, you can get the primary key and primary connection string. Just copy the primary connection string, this will help you to configure the CRM service endpoint in later.
We have done with azure bus creations successfully, will see how to create Cosmos DB and collections in the next part.
Do not forget to like and share this post. Happy Learning!