.NET CORE
MICROSERVICES
THE COMPLETE GUIDE
BHRUGEN PATEL
• What is Microservice?
• How to correctly implement Microservice?
OUTDATE COURSE!
EF Core
.NET Core
API
SQL
Server
VS 2022
.NET 8
Azure
Subscrption
WHY MICROSERVICES?
• Independently Deployable
• Independently Scalable.
• No Bulky Code.
• Reduce Downtime.
Course Overview
MICROSERVICES
Frontend Web
Application
PRODUCT
SHOPPING
CART
ORDER
EMAIL
User adds first item to the Cart
- Create Cart Header
- Create Cart Details
User adds a new item in the shopping cart. (User already has few other items in cart)
- Find Cart Header
- Add Cart Details under same Cart Header Id
User updates quantity of an existing item in the cart
- Find Details
- Update Count in Cart Details
Shopping Cart Logic
OAuth2 OpenID Connect
9
OAuth2 and OpenID Connect
● Built on top of Auth2
● Authorization
● Works with Access_token
DOCKER!
MULTIPLE
TECHNOLOGY
What this course is NOT about?
What this course is NOT about?
Client
Identity
Provider
IdentityServer 5 / Duende Identity Server
IdentityServer5
(Duende Identity Server)
● https://docs.duendesoftware.com/identityserver/v5
IdentityServer is an implementation of OpenID
Connect and OAuth2 and is highly optimized to solve
the typical security problems of today’s mobile,
native and web applications.
ASYNC AWAIT WITHIN CODE
Microservices
Application contains multiple loosely
coupled microservices
○ Individual Technology Stack
○ Communication between microservices
○ Separation of Concern
Microservices Application Flow
Gateway
.NET Identity
Shopping Cart
Order
Coupon
Email
Rewards
MVC
Application Product
Service
Bus
:7002
:7000
:7001
:7003
:7004
:7777
Traditional Monolith Application
ASP.NET Core Application
Product
Component
Shopping Cart
Component
Order
Component
Models
Views
Controller
Repository
Service
…
Models
Views
Controller
Repository
Service
…
Models
Views
Controller
Repository
Service
…
ASP.NET Core
Application
ASP.NET Core
Application
Microservices Application
ASP.NET Core Application
Product
Component
Shopping Cart
Component
Order
Component
Models
Views
Controller
Repository
Service
…
Models
Views
Controller
Repository
Service
…
Models
Views
Controller
Repository
Service
…
ASP.NET Core
Application
Models, Views, Controllers…
COMMUNICATION (SYNC/ASYNC)
SYNCHRONOUS COMMUNICATION -
 Synchronous communication was never a problem in relatively small monolithic
applications because it is a very simple concept to reason about.
 The client sends a request to the server, and the server responds to the client.
 An advantage of synchronous communication is that the service receives an
acknowledgement that the request was received, and the corresponding action was
executed.
ASYNCHRONOUS COMMUNICATION -
 When using asynchronous communication, the calling service does not wait for a response from the
called service.
 Asynchronous communication also allows the possibility of One-To-Many communication, where a client
can send a message to multiple services at once.
Microservices Application Flow
Gateway
.NET Identity
Shopping Cart
Order
Coupon
Email
Rewards
MVC
Application Product
Service
Bus
:7002
:7000
:7001
:7003
:7004
:7777
Identity Server Terminology
● Client
● Identity Resource
● API Resource
● Identity Token
● Access Token
Azure Storage Queue is a service for
storing large numbers of messages
Azure Messaging
Microsoft Azure Service Bus is a
message broker with message queues
and publish-subscribe topics.
Azure Service
Bus
Azure Storage
Queues
TOOLS NEEDED
01 03
SQL SERVER 2018
02 AZURE
SUBSCRIPTION
04
VISUAL STUDIO 2019 .NET 6
Microservices Application Flow (Without Gateway)
.NET Identity
Shopping Cart
Order
Coupon
Email
Rewards
MVC
Application Product
Service
Bus
:7002
:7000
:7001
:7003
:7004
Microservices Application Flow (With Gateway)
Gateway
.NET Identity
Shopping Cart
Order
Coupon
Email
Rewards
MVC
Application Product
Service
Bus
:7002
:7000
:7001
:7003
:7004
:7777
Client-to-microservice Communication
Client communicates directly with all the
microservices in this architecture.
Disadvantages of Client-to-microservice
Tight coupling Security Monitoring API
Adding a Gateway
● Single point of entry to set of services
● Easier Security Management
● Larger application
Disadvantages of Gateway
Tight coupling Extra layer Development
OVERVIEW
01
Here you could describe the topic of
the section
PRODUCT API BASIC
SETUP
02
BRIEF
INTRODUCTION
Venus has a beautiful name
and is the second planet
from the Sun. It’s terribly
hot—even hotter than
Mercury—and its atmosphere
is extremely poisonous
OVERVIEW
01
Here you could describe the topic of
the section
“This is a quote. Words full
of wisdom that someone
important said and can make
the reader get inspired.”
—SOMEONE FAMOUS
RabbitMQ
● Open-source messaging system
● RabbitMQ implements the AMQP protocol
● RabbitMQ Includes
○ Reliability
○ Routing
○ Browser based UI
○ Cross-platform
ASSIGNMENT – PRODUCT API
● Setup Product API Database / Tables
● Setup DbContext and Seed Product Table
● Setup AutoMapper
● CRUD functionality Product API
● Setup Authentication & Authorization in API
○ Create/Edit/Delete – ADMIN Role
○ Read – Any Authorized User
● Web Project to Consume API (Product API Port – 7000)
● Implement Product Service and Controller in Web
Project
● Views for Product CRUD Operations
EXCHANGE
Exchange Queue
RabbitMQ Message Broker
Routes
EXCHANGE TYPES
DIRECT
EXCHANGE
FANOUT
EXCHANGE
TOPIC
EXCHANGE
HEADER
EXCHANGE
DIRECT EXCHANGE
Direct
Exchange
Queue
RabbitMQ Message Broker
Routes
DIRECT EXCHANGE
Publisher
Direct
Exchange
Queue Consumer
RabbitMQ Message Broker
Routing Key = checkoutQueue
Routes
FANOUT EXCHANGE
Fanout
Exchange
Queue
RabbitMQ Message Broker
Routes
Queue
Queue
TOPIC EXCHANGE
Topic
Exchange
Queue
RabbitMQ Message Broker
Routes
Queue
Queue
Routing Key:
all.email.*
*.newCustomer.*
*.platinumCustomer.*
*.*.*
HEADER EXCHANGE
HEADER
Exchange
Queue
RabbitMQ Message Broker
Queue
Role = basicCustomer
Type= promotional
Role = platinumCustomer
Type= educational
QUEUES
Queue
Name Name of the queue
Durable Persist the queue to disk
Exclusive Delete queue when not needed
Auto Delete Queue deleted when consumer unsubscribes
BINDINGS
Exchange
Queue
RabbitMQ Message Broker
Queue
STANDARD QUEUE
Publisher Queue Consumer
RabbitMQ Message Broker
STANDARD QUEUE
Publisher
Direct
Exchange
Queue Consumer
RabbitMQ Message Broker
Routing Key = checkoutQueue
Routes
DIRECT ROUTING
Publisher
Direct
Exchange
Queue
Queue
Consumer
Consumer
RabbitMQ Message Broker
PaymentEmail
PaymentOrder
PUBLISH AND SUBSCRIBE
Publisher Exchange
Queue
Queue
Consumer
Consumer
RabbitMQ Message Broker

Microservices with Net Core 8 and Net Core 6