This service allows management of of key-values, abstracting the storage service semantic and presenting a simple interface to store data of any format using Azure Cosmos DB.
Values are organized in collections, it is possible to work on individual values and to fetch entire collections. Complex data structures are serialized by the clients and managed as simple text payload.
The service provides a RESTful endpoint to Create-Read-Update-Delete values, where each value has a unique Id referenced also as "Key", supporting concurrency.
IDs can be provided by the client or automatically generated by the service (i.e. Guids).
- Azure Cosmos DB account with API type DocumentDB
- Install Docker Compose: https://docs.docker.com/compose/install
- Create your Azure Cosmos DB account with API type DocumentDB
- Find your Azure Cosmos DB account connection string. See Update your Connection Strings if you need help finding it.
- Store the "Azure Cosmos DB account connection string" in the env-vars-setup script, then run the script.
- Run the Storage Adapter service using docker compose docker-compose up
- Use an HTTP client such as Postman, to exercise the RESTful API to create a collection.
- Install any edition of Visual Studio 2017. When installing check ".NET Core" workload. a. If you already have Visual Studio installed, then ensure you have .NET Core Tools for Visual Studio 2017 installed.
- Open the solution using the pcs-storage-adapter.sln file.
- Create your Azure Cosmos DB account with API type DocumentDB
- Open the solution in Visual Studio
- Either in the project properties Visual Studio or in your system, define the following required environment variables for the both the WebService
PCS_STORAGEADAPTER_DOCUMENTDB_CONNSTRING
= {your DocumentDB connection string}
- In Visual Studio, start the WebService project
- Using an HTTP client like Postman, use the RESTful API to create a simulation.
- Open the solution using the
pcs-storage-adapter.sln
file. - When the solution is loaded, go to
Run -> Edit Configurations
and create a new.NET Project
configuration. - In the configuration select the WebService project
- Add a new environment variable with name
PCS_STORAGEADAPTER_DOCUMENTDB_CONNSTRING
storing your DocumentDB connection string. - Save the settings and run the configuration just created, from the IDE toolbar.
- You should see the service bootstrap messages in IntelliJ Run window, with details such as the URL where the web service is running, plus the service logs.
This microservice contains the following projects:
- WebService.csproj - C# web service exposing REST interface for storage functionality
- WebService.Test.csproj - Unit tests for web services functionality
- Services.csproj - C# assembly containining business logic for interacting with Azure Cosmoze account with type DocumentDb
- Services.Test.csproj - Unit tests for services functionality
- Solution/scripts - contains build scripts, docker container creation scripts, and scripts for running the microservice from the command line
The scripts folder contains scripts for many frequent tasks:
build
: compile all the projects and run the tests.compile
: compile all the projects.run
: compile the projects and run the service. This will prompt for elevated privileges in Windows to run the web service.
The scripts
folder includes a docker subfolder with the files
required to package the service into a Docker image:
Dockerfile
: docker images specificationsbuild
: build a Docker container and store the image in the local registryrun
: run the Docker container from the image stored in the local registrycontent
: a folder with files copied into the image, including the entry point script
You can also start Device Simulation and its dependencies in one simple step, using Docker Compose with the docker-compose.yml file in the project:
cd scripts/docker
docker-compose up
The Docker compose configuration requires the IoTHub and StorageAdapter web serviceURL environment variables, described previously.
The service configuration is stored using ASP.NET Core configuration adapters, in appsettings.ini. The INI format allows to store values in a readable format, with comments. The application also supports inserting environment variables, such as credentials and networking details.
The configuration file in the repository references some environment variables that need to created at least once. Depending on your OS and the IDE, there are several ways to manage environment variables:
- For Windows users, the env-vars-setup.cmd script needs to be prepared and executed just once. When executed, the settings will persist across terminal sessions and reboots.
- For Linux and OSX environments, the env-vars-setup script needs to be executed every time a new console is opened. Depending on the OS and terminal, there are ways to persist values globally, for more information these pages should help:
- Visual Studio: env. vars can be set also from Visual Studio, under Project Properties, in the left pane select "Configuration Properties" and "Environment", to get to a section where you can add multiple variables.
- IntelliJ Rider: env. vars can be set in each Run Configuration, similarly to IntelliJ IDEA (https://www.jetbrains.com/help/idea/run-debug-configuration-application.html)
Please follow our contribution guildelines. We love PRs too.
Please enter issues, bugs, or suggestions as GitHub Issues here: https://github.com/Azure/pcs-storage-adapter-dotnet/issues.