The goal of this series is to introduce some of the technologies we use at Trimble MAPS. We’re going to build a web application that will accept HTTP messages from a client, publish them to a RabbitMQ message queue, then consume those messages from the queue. We’ll also use Docker to run each application in a container, and Docker-Compose to orchestrate the launch of all of our containers. If any of those terms are unfamiliar, don’t worry, each one will be explained as we approach it. The first part of this tutorial will focus on .NET Core.

Part 1: .NET Core (source code can be found on Github)

.NET Core is an open source software development framework, and effectively the successor to Microsoft’s .NET Framework. It’s been steadily growing in popularity among developers thanks to a few significant differences from previous iterations of .NET. Foremost among these is cross-platform support — applications can be built on Windows, Linux, or MacOS, and once built, will run on any of those platforms. The lightweight nature of .NET Core also make it an ideal choice for containerization. Combining those two attributes leads to a common industry use case — building apps on Windows, but running them in Linux containers to improve performance and reduce operating costs.

Let’s create two apps: a simple WebAPI to accept HTTP POST requests, and a console app to send those messages to our WebAPI. The only prerequisites for this are Visual Studio Code and the .NET Core 2.2 SDK.

First, create a new folder to serve as the root directory of our project, and open a command prompt pointing to that directory. We’ll use the dotnet CLI tool to create our solution and skeleton apps for our projects. Run the following commands:

The first line creates a new ASP.Net Core WebAPI project in a sub-directory called publisher_api. The next two commands create a solution in our root folder, and add the publisher_api project to that solution.

Now, we already have a working web service! We can test it out by executing “dotnet run” from the publisher_api directory and then visiting https://localhost:5001/api/values in our web browser.

Output from our publisher_api project

Let’s open our solution in Visual Studio Code and see what we’ve created. In our command prompt, enter “code .” from the root directory to launch the IDE and browse our project.

Startup.cs and Program.cs contain the boilerplate necessary to run our small web service. They are important, but their details are beyond the scope of this tutorial. Instead, let’s look inside the Controllers folder and examine ValuesController.cs. In ASP.Net Core, controllers are responsible for handling incoming HTTP requests. When we entered localhost:5001/api/values in our browser, we sent an HTTP GET request to the Values controller. The response we saw in the browser is returned from the designated GET method in that controller:

Just below the default Get method, you’ll see another Get function defined, but this one takes an int as a parameter. If we enter https://localhost:5001/api/values/2 in our browser, our request will be routed to that function (and ‘2’ will be the value of the ‘id’ parameter). We’ll also see a different response in the browser.