Wednesday, May 1, 2019

Introduction to Azure CosmosDB Emulator


  


      CosmosDB Emulator is a must have tool if you develop applications for Azure CosmosDB. Also, it’s a great tool to have if you like to learn about Azure CosmosDB but you have limited access to Azure for any reason. Azure CosmosDB team constantly works to make all available tools better including the emulator. Currently, emulator supports SQL, Cassandra, MongoDB, Gremlin and Table API. Data Explorer feature supports only SQL API for now. Emulator'simplementation is different than the service and you should not use it for stress testing, you can not test global replication or latency for read and writes.

    To start, you can download the emulator from MS Download Center or you can get the docker version and run the emulator on Docker for Windows. Emulator will need to adjust firewall rules and create certificates to use so you will need to have admin rights. When you launch the application, you should see its UI in your browser. 



     As you might notice, in the QuickStart page you see connection string for SQL API and Mongo API. Emulator supports Cassandra API, Gremlin API and Table API too. If you like to use one of them then you need to start the emulator by passing special parameters from the command line. (CosmosDB’s default path is C:\Program Files\Azure Cosmos DB Emulator.)



     To be able to use Cassandra API, you need to start the emulator with “/EnableCassandraEndpoint” parameter. If you like to change the port of Cassandra API, you can use the “CassandraPort” parameter to override the current port.


     To be able to use Table API, you need to start the emulator with “/EnableTableEndpoint” parameter. You can override Table API port by using "/TablePort" parameter.




     To be able to use Gremlin API, you need to start the emulator with “/EnableGremlinEndPoint” parameter. You can override Gremlin's port by using "/GremlinPort" parameter.


   CosmosDB Emulator has some other interesting features too. For example, you can make the emulator available to your local network by using "/AllowNetworkAccess" parameter. You need to pass the key string by using "/key" and the name of the key file to by using "/keyfile" parameter to make it work. To pass key and key file, we need to generate a key file first. In the following example, I am using the "/GenKeyFile" parameter to do that. I need to pass the name of the key file to make it work.


    File should be created in the CosmosDB Emulator folder. View the file with Notepad, It should have a key string in it. Copy the key to use in the "/key"parameter.


    If the key is correct and CosmosDB can find the file you specified, you should see the folowing window. This is the step CosmosDB will adjust your computer's firewall settings  so other computers in your network can access to the Azure CosmosDB emulator on your computer. 


   As you can see, Emulator can do more than just emulating SQL API and Mongo API. There are some other features that I haven't covered here. You can find all other available options by passing "/help" parameter.

No comments:

Post a Comment