
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.
Explain how an api gateway acts as a single entry point for microservices. Highlight authentication, logging, tracing, service discovery, and IP whitelisting, with ocelot as a .net core option.
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.
Connects API gateway with product service using MassTransit and RabbitMQ; adds CreateProductHandler as the consumer for CreateProduct, configures the endpoint with prefetch 16 and retry, and starts the bus.
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.
Explore the cqrs design pattern and why to separate read and write operations in microservices for improved scalability and performance, including event sourcing and change capture.
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.
Create a product query by adding GetProductById, implement GetProductByIdHandler as an IConsumer, inject productservice, and respond with product details via RespondAsync; wire RabbitMQ, request client, and API gateway.
Execute a postman get request to fetch product details via the Product.Query API, wire GetProductByIdHandler with scoped services, and configure MongoDB, RabbitMQ, and DbInitializer for CQRS data access.
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 cross-service user login in asp.net core 3.1, connecting the api gateway to User.Query.API with a LoginUser model, login handler, and encrypted password verification using rabbitMQ and MongoDB.
Install JWT libraries from NuGet to enable OpenID Connect bearer tokens, adding Microsoft.AspNetCore.Authentication.JwtBearer and Microsoft identitymodel.Token in an Authentication folder of the Infrastructure project, preparing for JWT token implementation.
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.
Practice unit testing the add method of ProductController by mocking external dependencies with Moq (IBusControl and IRequestClient), configuring GetSendEndpoint, and asserting a 202 accepted response with product created.
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.
Refactor test setup by moving product controller initialization into a shared setup method, replacing per-test code, and show how tests reveal breaking changes guarding against regressions.
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.
Discover how benchmarking reveals an application's performance under workload, answering how many users it can handle at once and how fast each request executes, using Apache Bench.
download apache 2.4.48 win64 from apache lounge, extract to the c drive root, and install via httpd.exe -k install; verify ab is available and ensure visual c++ redistributable is installed.
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.
Benchmark the GetProduct API with ab to measure requests, concurrency, latency, and throughput. Export metrics from the test on localhost to assess performance.
Explore resiliency in microservices by recovering from failures while staying functional, using Polly from NuGet to apply fallback, retry, circuit breaker, timeout, and bulkhead isolation.
Learn to handle downstream failures in a .NET Core 3.1 microservices app using Polly's async fallback policy for IActionResult, returning a content result on exceptions.
Implement a retry policy that handles transient errors by retrying up to three times before returning a fallback message, and combine policies with PolicyWrap and wait and exponential backoff.
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.
Install Redis on windows using the msi package, configure port 6379 and firewall exceptions, then verify by setting and getting a key-value entry in the Redis cli.
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.