This blog post provides a quick overview and demo of how you can use the Azure Cosmos DB Linux Emulator on Docker (in preview at the time of writing) along with Visual Studio Code in order to enhance your local development experience.
Since the Azure Cosmos DB Linux Emulator is readily available as a Docker image (simply docker pull mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator
), it’s easy to incorporate it within your existing setup. For instance, it could be in a docker-compose
file as a part of a larger stack (here is an example of how to use it with Apache Kafka). However, complementing it with the Visual Studio Code Remote – Containers extension, gives you the ability to leverage a Docker container as a full-fledged development environment.
Say you want to build an app with Azure Cosmos DB Core (SQL) API and the Java SDK, and you have VS Code and Docker (optionally Docker Compose) available. Just create a JSON configuration file (called devcontainer.json
) to define your stack. You can then spin up an environment on-demand with just a few clicks – this will constitute one or more Docker containers along with the entire operating system, programming language runtime (Java in this case), toolset, etc. which you originally specified in devcontainer.json
.
Some of the obvious benefits of using the emulator include: it’s cost-effective (free!), convenient for scenarios when your app has other components (e.g. messaging systems) and great for iterative development/prototyping/demos since setting up and tearing down the environment is easy, consistent and error-free (in most cases!)
How to use the Azure Cosmos DB Linux emulator with VS Code
Use the instructions in this GitHub repo to get started quickly. It is based on the original sample code repo for Azure Cosmos DB Java SDK for SQL API with added files to enable “Visual Studio Code Remote – Containers” experience.
You can also follow along with the video that shows all of this in action:
This example can be extended to any Java application. All you need to do is add the .devcontainer folder to your current project and (maybe) tweak a few things depending on your requirement for e.g. the Java version.
What this demonstrates is just the tip of the iceberg and you could leverage it in so many interesting ways. I look forward to hearing how you use it!
More resources
- Find more ways to dev/test free with Azure Cosmos DB
- Download the Azure Cosmos DB local emulator
- Review technical documentation for Azure Cosmos DB
0 comments