
In this video, we will look into microservice basics and what type of problems, it solves.
This video will explain what we are going to build in this course and what services we will be building on top of ASP .Net Core and MongoDB NoSql Database.
In this video, we will structure our application in Visual Studio 2019.
We will Create the following (Project Setup only) :
API Gateway Project.
Product API (First Microservice)
User API (Second microservice)
Order API (Third microservice)
EShop Infrastructure (Class library).
Explore command and event patterns in microservices: commands are simple objects with no business logic that change data and emit events, using imperative names (CreateOrder) and past-tense event names (OrderPlaced).
Define commands and events in EShop.Infrastruture, adding CreateProduct and ProductCreated models. Expose Get and Add methods in EShop.ApiGateway's productController, returning 202 with productCreated and the string "get product method called".
In this video, we will learn what is Postman, and how to use it to test our application API endpoints.
You will be able to understand what is MongoDB and Robo3T.
You will be able to install MongoDB and Robo3T.
You will be able to implement application and MongoDB connectivity.
Develop a product service in the product api with IProductService and ProductService, implementing GetProduct and AddProduct returning ProductCreated, and a repository using IProductRepository and ProductRepository with MongoDB integration.
Configure MongoDB in startup by adding a MongoDB node in appsettings.json, register IProductService and IProductRepository with AddScoped, and wire ProductController to use ProductService for fetch and create.
Save a product to MongoDB in a .NET core 3.1 microservice. Implement AddProduct and GetProduct with async/await and map _id using BsonId.
Understand Mongo conventions, map product ids with BSON id and BSONRepresentationType.ObjectId, switch ProductId from Guid to string, and configure ConventionPack with ignore extra elements, camel casing, and enum representation.
Discover RabbitMQ, a leading open-source message broker, and MassTransit, a .NET framework that enables reliable, asynchronous publisher/consumer communication across microservices using AMQP exchanges, bindings, and queues.
Learn how to install RabbitMQ and Erlang on Windows, start the RabbitMQ server on port 15672, and access the dashboard with the guest credentials.
Install RabbitMQ and create a shared event bus extension. Bind a RabbitMQOption from appsettings, configure MassTransit, and wire a host connection for RabbitMQ in the API gateway.
Connect user requests to the product service via an api gateway using a message bus, injecting IBusControl and configuration to send messages and verify with MongoDB. Preview cqrs concepts.
Refactor the product api by adding a dedicated query api and a shared data provider, moving services and repository code, updating namespaces, and adding references for the CQRS setup.
Explore the separation of concern between commands and queries, choosing logical or physical separation based on project scope within a microservices context.
Set up a .NET Core 3.1 user service with MongoDB by configuring startup settings, creating CreateUser and UserCreated, implementing UserRepository and IUserrepository, and wiring UserService via dependency injection in configureServices.
Copy rabbitmq connectivity code from product.api to user.api's startup, add the rabbitmq connection string in appsettings, and configure CreateUserHandler as a consumer for the add_user queue via Masstransit.
Create a security layer with IEncrypter and Encrypter to generate salts, hash passwords with RFC2898DerivedBytes, inject into the user service, and add set password and validate password extensions.
Refactor the user service by migrating extension, repository, and service folders into EShop.User.DataProvider. Adjust namespaces, remove old dependencies, and prepare startup references to the data provider.
Implement a jwt based authentication flow in dotnet core by defining IAuthenticationHandler, jwt options, and a token generator with signing key, issuer, expiry, and an extension to add jwt support.
Configure jwt with secret key, expiry, and issuer in appsettings and api gateway, generate tokens on login, and enforce jwt bearer authorization to protect the add product endpoint.
Explore why unit testing matters for microservice components like API gateway, consumers, and handlers, and learn how small tests reveal breaking changes early, with an introduction to NUnit.
Create a NUnit test project named EShop.ApiGateway.Test, install and update NUnit packages, and run a simple test1 decorated with Test and Assert.Pass to validate the ApiGateway methods.
Unit test the get method of the product controller by mocking the requestClient, simulating a GetResponse of ProductCreated, and asserting an AcceptedResult with the expected product.
Learn how to unit test the LoginUserHandler using an in-memory Masstransit test harness, mocking the user service, encrypter, and auth handler to validate passwords and return a token.
Benchmark the application's throughput by simulating multiple users and requests with Apache Bench, adjusting n and c to test the GetProduct API and capture average time and requests per second.
Learn to use ab, the apache bench command, to test API endpoints with get and post requests, using -n and -c for requests and concurrency, with payload and header options.
Implement a circuit breaker policy in .NET Core 3.1 to fail fast after consecutive failures, open the circuit on errors, and use a fallback to return a custom message.
Apply Polly's advance circuit breaker to monitor failure rate with failureThreshold, sampleDuration, minimumThroughPut, and durationBreak, opening the circuit when 50% of requests fail in 30 seconds.
Learn how bulkhead isolation controls resources in microservices, using execution and queue slots to prevent cascading failures and keep services responsive under load.
Set up the eshop cart api, define cart and cart item models, implement repository and service for add and remove, and create consumers to process cart events via data provider.
Connect the cart API to Redis with stackexchange redis cache, configure host and port, and wire the cart repository and service with mass transit add-cart-item and remove-cart-item consumers.
Validate the cart api by sending a postman request with cartId, amount, and items, troubleshoot redis errors by downgrading nuget to 5.0.1, and verify data with redis cli using hgetall.
Note: This course focuses on the architecture and core concepts of microservices, which remain largely the same across .NET versions. While the hands-on demonstrations use .NET Core 3.1, the concepts and design principles apply equally to newer versions of .NET.
Curriculum:
Learn the basics of microservices and what problem it solves.
Learn the basics of the components of the microservices (API Gateway, Message Brokers, Services, Database).
Implement a microservice architecture with event-driven communication using ASP.NET Core, RabbitMQ, Masstranit, and MongoDB.
Learn microservice by following step-by-step coding tutorials and implementations of key concepts.
Learn Masstransit and its features to work with message brokers like RabbitMQ, ActiveMQ, or Azure Service Bus.
Connect Microservice with MongoDB and use Robo3T for viewing MongoDB data.
Learn Postman tool installation and its basics.
Learn fundamentals of AMQP (Advanced Message Queuing Protocol) and RabbitMQ and its exchanges.
Learn API Gateways and how to communicate between API Gateway and microservices over RabbitMQ Message Broker.
Learn fundamentals of CQRS (Command Query Segregation Principle).
Implement Authentication and Authorization in microservices using JSON Web Tokens.
Learn the necessary tools required in the microservice ecosystem.
What is Benchmarking and Apache Bench Installation to micro-benchmark our application?
Learn how to unit test APIs and Masstransit Events Consumers using NUnit.
Learn to write resilient microservices using Polly (a fault-tolerant library ) by implementing Policies.
Learn to integrate Swagger Documentation with microservice for API endpoint documentation and testing.
Learn to integrate Redis (In Memory database) with Microservice and perform CRUD operation.
Learn what are distributed transactions and how to implement distributed transactions in microservices.
What is Routing Slip Pattern?
Implementing Routing Slip pattern using Masstransit Courier to handle the distributed transaction.
What is Idempotency in microservices and why is it necessary?
Implementation of idempotent microservice using Idempotent Consumer Pattern.