260
CHAPTER 6 | Tackle Business Complexity in a Microservice with DDD and CQRS Patterns
Use MongoDB API for local dev/test Linux/Windows containers plus Azure Cosmos
DB
Cosmos DB databases support MongoDB API for .NET as well as the native MongoDB wire protocol.
This means that by using existing drivers, your application written for MongoDB can now
communicate with Cosmos DB and use Cosmos DB databases instead of MongoDB databases, as
shown in Figure 7-20.
Figure 7-20. Using MongoDB API and protocol to access Azure Cosmos DB
This is a very convenient approach for proof of concepts in Docker environments with
Linux
containers because the
MongoDB Docker image
is a multi-arch image that supports Docker Linux
containers and Docker Windows containers.
As shown in the following image, by using the MongoDB API, eShopOnContainers
supports MongoDB
Linux and Windows containers for the local development environment but then, you can move to a
scalable, PaaS cloud solution as Azure Cosmos DB by simply
changing the MongoDB connection
string to point to Azure Cosmos DB
.
261
CHAPTER 6 | Tackle Business Complexity in a Microservice with DDD and CQRS Patterns
Figure 7-21. eShopOnContainers using MongoDB containers for dev-env or Azure Cosmos DB for production
The production Azure Cosmos DB would be running in Azure’s cloud as a PaaS and scalable service.
Your custom .NET containers can run on a local development Docker host (that is using Docker for
Windows in a Windows 10 machine) or be deployed into a
production environment, like Kubernetes in
Azure AKS or Azure Service Fabric. In this second environment, you would deploy only the .NET
custom
containers but not the MongoDB container since you’d be using Azure Cosmos DB in the
cloud for handling the data in production.
A clear benefit of using the MongoDB API is that your solution could run in
both database engines,
MongoDB or Azure Cosmos DB, so migrations to different environments should be easy. However,
sometimes it is worthwhile to use a native API (that is the native Cosmos DB API) in order to take full
advantage of the capabilities of a specific database engine.
For further comparison between simply using MongoDB versus Cosmos DB in the cloud, see the
Benefits of using Azure Cosmos DB in this page
.
Dostları ilə paylaş: