Step by step implements CQRS in microservice

Step by step implements CQRS in microservice

May 31, 2021 0 By Nam Vu

Take notes:

Analytic:
– Feature in service
– Domain Entity in service
Ex: Login: AspNetUser, Farmer

Implement:
– Create Dto in protobuf file + include project
– Create fuction query/mutation type with name graph api
– Create input/output for query/mutation inherited protobuf
– Create query/mutation function call query/command
– Create query/command class
– Create validator class inherited input query/mutation and handle vaidate input
– Create hanlder class inherited query/command class
– Call validator in hanlder class and implement feature in herer

Communication grpc:
Ex: Tranfer data between Personal Data Service and Identity Service
– Define contract request/response of rpc in protobuf file
– With source service:
+ Add more subscribe grpc protocol of target service to startup
+ Define service class with name target service and handle all function communicate in this class
+ Injection that service class in startup to use it
+ Use function that defined in your methods
– With target service:
+ Add more publish grpc protocol of target service to startup
+ Define target service class implement RPC of protobuf file via override methods
+ From rpc override method call query/command class with handle function in target service

Communication event bus:
Ex: Send event from Personal Data Service to Communication Service and handle send email in Communication Service
– Create a model for the event bus with CorrelationId
– With source service:
+ Add more subscribe queue messages of rabbitMQ in the startup
+ Call send messages with the defined model below in your functions
– With target service:
+ Add more publish queue messages of rabbitMQ in startup
+ Define consumer class handler action after receive messages


#NtechDevelopers