What’s New for Developers in Azure Cosmos DB
What’s New for Developers in Azure Cosmos DB
Take a look at what Microsoft has introduced in their latest version of their database service.
Join the DZone community and get the full member experience.Join For Free
For those of you that are new to the service, Cosmos DB is a global distributed multi-model database service, that allows you to read and write data from any Azure region with single-digit millisecond latency for both reads and writes,
Developer Update Highlights
.NET SDK Version 3.0 (Preview)
.NET SDK Version 3.0 targets .NET Standard 2.0, has a new intuitive object model designed to be easier to use, support for streams and performance improvements, and also it is open source on GitHub.
Database-level Throughput – 25x Lower Entry Point
This will enable you to make a new database, put as many containers as you want inside and have them all share the same throughput of the database.
Azure Pipelines Cosmos DB Emulator Build Tasks
Azure Pipelines Cosmos DB build task allows you to run tests against Cosmos DB emulator in your CI/CD pipelines.
A Real Example
Let’s see an example. Now I am going to create a new database with Cosmos DB in just one line (image 1). I will start with this ".database equals to this.cosmosClient" which is the entry point to interact with a Cosmos DB service. Off this Cosmos Client, we see that there is a new databases property off which we can access every method relevant to databases. In this case, I’ll use the
CreateDatabaseIfNotExistsAsync method, giving the
databaseId . I’ll put a wait in front of it, and now I’ve created a new database in just one line with Cosmos DB.
Image 1 – Create a new database in just one line with Cosmos DB
With the new SDK the object model is updated and also API surface is updated to be more modular. Now, as a result, we have a database object, a container object, and items, each with their own relevant methods. After we run the code, the resources in Cosmos DB (database container and item) will be actually created. If we check in the portal, navigate to data Explorer that is the one-stop shop for viewing all the data and the Cosmos DB containers. After refreshing, we can see that our “to do” database and “to do” container have both been created. If we open the “Documents” we can see that it is the same item which we created via console app (image 2).
Image 2 – Data explorer
If we take a closer look at our “to do” container, if we go to “Scale & Settings,” we can see more information about Scale and Conflict resolution (image 3).
Image 3 – Scale & Settings
Next, we will see a dev-test experience with an ASP.NET web application running again Cosmos DB. Actually, it is running against our local emulator. The emulator runs on Windows machines and allows you to emulate the Cosmos DB service locally, so you can do operations like creating databases and containers, running unit tests etc without incurring any cost on the Cosmos DB service. Now I will run my already created unit tests, which will create a new container, create a new database, add some items to it, test a query, running against a local version of the emulator.
Now also you can do the same thing in CI/CD pipeline. I have already a pipeline setup, which builds my web app, run some tests, and deploys it to azure app service. I just need to add my Cosmos DB emulator build task (image 4), which I can get it free from the Azure DevOps marketplace. There I should just specify that I want to use the endpoint emitted by the emulator container earlier in this pipeline.
Image 4 – Run Azure Cosmos DB Emulator container
After that, I can queue my build. On the image 5 you can see the log details.
Image 5 – Detailed logs of the Azure Cosmos Emulator DB container
This build task makes it a lot easier to use the Cosmos DB in CI/CD, meaning, you no longer need to deal with manually setting up a container and manually setting the emulator and getting it to run.
Azure Cosmos DB is Microsoft’s globally distributed multi-model database service. With the click of a button, Azure Cosmos DB enables you to elastically and independently scale throughput and storage across any number of Azure’s geographic regions. You can elastically scale throughput and storage, and take advantage of fast, single-digit-millisecond data access using your favorite API among SQL, MongoDB, Cassandra, Tables, or Gremlin. You can try Azure Cosmos DB for Free without an Azure subscription, free of charge and commitments. Try all the above mentioned and stay up-to-date on the latest Azure CosmosDB news and features.
Published at DZone with permission of Mohamed Radwan , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.