Cosmos DB Emulator
Set up Cosmos DB Emulator locally
The Azure CosmosDB Emulator provides a local environment that emulates the Azure Cosmos DB service for development purposes. Using the Azure CosmosDB Emulator, you can develop and test your application locally, without creating an Azure subscription or incurring any costs. Latest instruction can be found in here
Using the Cosmos DB Emulator to run the database locally
Download and install the latest version of CosmosDB Emulator. Once it's installed, it will be available on localhost.
- Unix
- Windows
You can also find the Emulator from Start Menu and type Azure CosmosDB Emulator.
The CosmosDB Emulator service is primarily a Windows service, so using it in Unix/Linux/MacOS requires a few
additional steps. One of the simplest ways of running the emulator is to download
the Linux Emulator for Docker.
Please follow the installation instructions, with one exception: when running the Docker image, don't set
the AZURE_COSMOS_EMULATOR_IP_ADDRESS_OVERRIDE=$ipaddr
. Instead, set it to 127.0.0.1
.
The value for COSMOSDB_KEY
can be found within the emulator. See Primary Key:
Please, take a note of the cosmosdb URI, databaseName and key, as they will be needed to configure the application in a further step.
Create the Cosmos DB structure
Based on the template the CosmosDB has to contain a fixed structure.
Create a collection Stacks
with a container id menu
and the partition key /id
.
Create a database called Ensono Stacks for the application, and a database called CosmosDBPackage
for the
integration tests of the CosmosDB package (using the same container id and partition key as the main database).
The Ensono Stacks database should have a container called Menu partitioned by /id.
Export Azure Cosmos DB Emulator certificates to use in the Java Application
- Unix
- Windows
Start the Windows Certificate manager by running certlm.msc and navigate to the Personal->Certificates folder and open the certificate with the friendly name DocumentDbEmulatorCertificate.
Follow the steps in Export the Azure Cosmos DB TLS/SSL certificate Also Export CosmosEmulatorSecretes following the above link.
Determine which root certificates have been installed
Follow the steps to determine which root certificates have been installed Add Root certificate
Now import the documentdbemulatorcert and CosmosEmulatorSecrets certificate.
keytool -keystore "location to download the root certificate" -cacerts -importcert -alias documentdbemulator -file "location of documentdbemulatorcert.cer"
type the password when prompted "changeit" (This should be the same if you haven't changed it when listing the certificates). If asked "do you trust this certificate" type in "y".
follow the above steps to import cosmosemulatorsecrets certificate
keytool -keystore "location to download the root certificate" -cacerts -importcert -alias cosmosemulatorcert -file "location of cosmosemulatorsecrets.cer"
Go to URL in your browser:
Firefox -- click on HTTPS certificate chain (the lock icon right next to URL address). Click "more info" > "security" > "show certificate" > "details" > "export..". Pickup the name and choose file type example.cer.
Chrome -- click on site icon left to address in address bar, select "Certificate" -> "Details" -> "Export" and save in format "Der-encoded binary, single certificate".
Now running the below should list 4 certificates.
keytool -list -keystore cacerts
Download the certificate
curl -k https://localhost:8081/_explorer/emulator.pem > emulatorcert.crt
Import to Java trust store
keytool -importcert -cacerts -alias documentdbemulator -file <path to emulatorcert.crt>
In order to make sure the certificate is there, you can run the following:
keytool -list -cacerts | grep -A1 documentdbemulator