nhatthaiquang-agilityio / NET5-Microservices-Using-MassTransit

Example: .NET 5 Microservices using MassTransit with RabbitMQ or Amazon SQS & SNS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NET5-Microservices-Using-MassTransit

Example: .NET 5 Microservices using MassTransit. It is easy to use and migrate from RabbitMQ to AmazonSQS and SNS for each environments.

+ RabbitMQ
    - Direct Queue(queue:consumer-consumers-order)
    - Exchange Topic: notification
        - Topic=email: will be received by EmailService
        - Topic=push: will be received by Notification
+ Amazon SQS and SNS
    - Direct Queue(queue:consumer-consumers-order)(Topic:Messages_Commands-Order),
        create a queue and create a SNS Topic which link the queue
    - Topic:Messages_Commands-INotification, Routing key: "push" and "email"

Requirements

Structures


  • Producer: using the API sends messages
  • Consumer: receive messages from Queue(consumer-consumers-order)
  • Notification: receive messages with Exchange=notification and Topic=push
  • EmailService: receive message with Exchange=notification and Topic=email
  • Messages: create message model and Service Connection Config for RabbitMQ and AmazonSQS

Overview


  • Direct Queue

    Direct Queue

  • Topic

    Topic

Usages

RabbitMQ Server


  • Start RabbitMQ Server
    cd DemoMicroservices
    docker-compose up
    

Amazon SQS and SNS


  • Create a user in IAM: add SQSFullAccess and SNSFullAccess
  • Set and add Region, AccessKey and SecretKey into MessageBusSQS in appsettings.json
    "ConnectionStrings": {
        "MessageBus": "amqp://admin:password@localhost:5671/",
        "MessageBusSQS": "[AccessKey]:[SecretKey]@[region]"
    },
    "UsingAmazonSQS":"true"
    
Direct Message

  • Amazon Queue(Direct Queue:consumer-consumers-order)

    Direct-Queue

  • Create topic SNS Endpoint: arn:aws:sqs:ap-southeast-1:783560535431:consumer-consumers-order

    Topic with SQS Queue

  • Monitor SQS

    Monitor-Queue

Topic

  • Amazon Topic SNS

    Topic-SNS-To-Queues

  • Subcription Topic with SQS, and set RoutingKey

    Subscriptions-Topic

Run


  • Start multi apps with Visual Studio

  • Run Producer: http://localhost:22270/swagger/index.html

    • Send a message to Queue(consumer-consumers-order), Run post Order API

      http://localhost:22270/Order
      
    • Send a message to Email Service, run post Notification API

      http://localhost:22270/Notification
      
      {
          "notificationId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
          "notificationType": "email",
          "notificationContent": "email body",
          "notificationAddress": "nhat.thai@example.com",
          "notificationDate": "2021-12-06T04:31:16.654Z"
      }
      
    • Send a message to Notification, run post Notification API

      http://localhost:22270/Notification
      
      {
          "notificationId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
          "notificationType": "push",
          "notificationContent": "body",
          "notificationAddress": "",
          "notificationDate": "2021-12-06T04:31:16.654Z"
      }
      

References


About

Example: .NET 5 Microservices using MassTransit with RabbitMQ or Amazon SQS & SNS


Languages

Language:C# 76.2%Language:HTML 12.5%Language:Dockerfile 6.0%Language:CSS 4.5%Language:JavaScript 0.8%