It’s been a while since I published the latest article, but it’s high time to finally get into the topic of microservices for real. Does open source, .NET Core, distributed system, Docker and other cool words sound good to you? If that’s the case, stick with me and let me guide you through the world (or at least part of it) of microservices. This is going to be the very first article (an introduction) of the upcoming series.





Foreword

A few months ago, I had an idea to publish a detailed course about implementing microservices in .NET Core. It turned out, that a friend of mine, Darek, thought of a similar concept – so we teamed up, created the distributed application (available on GitHub) and gave a few lectures (close to 10) during IT events and conferences, here in Poland. The idea of the recording a video course is still there (and sooner or later, it will be published), yet for now, we need to polish some remaining bits of the application.

Nevertheless, whether you are a microservice expert or beginner, read a book published by Microsoft and studied the eShopOnContainers repository (or not), let me introduce you the DShop (Distributed Shop), a brand new solution, containing over 15 repositories, including API Gateway + 8 microservices written totally from the scratch using the latest version of ASP.NET Core (2.1.1), hopefully, a starting point for some of you, who wanted to get into the world of microservices hype but had no idea where to start, or got stuck somewhere during the journey.

DShop

As before mentioned, DShop stands for an acronym of Distributed Shop, simple as that.

Why another online shop? For a single reason – this domain is usually understood by all of the people (including developers) at least at its very basic level – products, shopping carts, orders etc. If you’re into the world of DDD, these are also pretty good bounded contexts, that can be treated as separate microservices. And trust me – we (Piotr and Darek, the core developers behind the project) made everything as simple as possible (besides some generic reflection magic and other quirks), so you should be able to understand quite fast what’s going on, simply by looking at the domain models or application services (handlers).

Source

The whole idea behind DShop was to make it for you – the programmers, so that you can take a look at the code, play with it, validate your own ideas, copy our code and use it in your own projects, or point out our mistakes – whatever makes you a better software developers and provide the valuable content. Thus, you can download the whole source code from GitHub, just keep in mind that we update the repositories from time to time, fix bugs, refactor the code and extend some features – it’s an ongoing project.

Tech

One of our goals was to make the solution agnostic from cloud providers that offer some special services (e.g. Azure Service Bus or AWS Lambda). Basically, you can run DShop anywhere – on local machine, private server or in any cloud. Let’s have a glimpse, what technologies and tools are being used to make it work:

.NET Core – API Gateway and all microservices are written in C# and ASP.NET Core (2.1.1)

RabbitMQ – one of the most popular message buses out there and RawRabbit as client library

MongoDB – NoSQL databse to store the services data

Redis – extremely fast caching server, an ideal choice for distributed systems

Docker – containers are everywhere, so Dockerfile for each service and Docker compose on top of it

Travis CI – build service, free to use for open source projects hosted on GitHub

Docker Hub – Docker images repository, where DShop images are being published

Rancher – enterprise management for Kubernetes, open source and easy to use

There are of course some other tools or libraries being used e.g. Angular 6 for the web application (not finished yet), but let’s leave it for now, we’ll talk about them in the next posts.

Start

Each project has its own repository. We’ll discuss the solution structure in the upcoming articles, but these are the most important projects (besides the bash scripts, that were simply copied from the base DNC-DShop repository).



In order to start DShop you need to have RabbitMQ, MongoDB, and Redis up and running (not to mention the latest version of .NET Core SDK). You can also easily start these through Docker – just take a look at the following script.

Once the required services are available, you can start either one by one or via Docker all of the microservices (projects named DShop.Services.Xyz, a total number of 8) and the API Gateway (DShop.Api). You can also make use of this script that loops through each repository and starts the project – just keep in mind to put that into the root directory, where the remaining projects are (as shown on the screen above).

Assuming that everything is up and running, you shall find the DShop.rest file that uses REST Client extension for the VS Code – give it a try and send a few HTTP requests to the API.

That being said, I encourage you to explore the source code and play with it. Stay tuned, as in the next posts we’ll go through the particular microservices implementation, talk about the distributed systems pros & cons and many, many other concepts that sometimes are not clearly visible at the first glance.

Oh, and finally – check out the DevMentors.io and subscribe to our social media channels, if you want to know once the video course will be completed.

P.S.

If you know Polish, take a look at the following video that was recorded quite recently – here, we talk about the DShop and core aspects of microservices.