DEV Community

Cover image for .Net AWS MQ
fullstackcodr
fullstackcodr

Posted on

.Net AWS MQ

Disclaimer: In this article I give a brief on how to interact with Amazon MQ (using the ActiveMQ engine) from a .Net6 application via MassTransit providing boilerplate code and instructions. This is a high overview and not a step by step guide. Finally, English is not my first language, so my apologies for any mistakes.

What are we building
This is a Proof of Concept aiming to demonstrate the integration of AWS AMQ (Pub/Sub) into .Net via MassTransit. In this repository there are two elements under a single Solution:

  1. WebApi Project containing an ApiController and endpoint which is allowing posting to AMQ via a MessagingService
  2. A console (dummy) application which consumes the messages from the previous step

Prerequisites
It is expected to have an AWS Account.

Create a broker
This is an extensive and descriptive enough tutorial on how to create an AMQ broker. Just to highlight that AmazonMQ supports two engines: ActiveMQ and RabbitMQ. We are going for the ActiveMQ option. The broker creation process takes approximately 15-20 minutes to complete.
Important: Make sure to use one of the smaller EC2 instances and not the default large one.

Setup the project
To make the project up and running there are few actions to be taken:

  • Replace the credentials in the (Producer) WebApi project ( appsettings.json ):
  "AMQ": {
    "Username": "{broker_username}",
    "Password": "{broker_password}",
    "HostUrl": "activemq://{broker_endpoint}",
    "queueName": "{broker_queue_name}"
  }
Enter fullscreen mode Exit fullscreen mode
  • Replace the credeitnals in the (Consumer) Console Application:
string username = "{broker_username}";
string password = "{broker_password}";
string hostUrl = "activemq://{broker_endpoint}";
string queueName = "{broker_queue_name}";
Enter fullscreen mode Exit fullscreen mode
  • Start both projects in parallel. To achieve this, right click on the Solution and through the properties: Image description

Demo
Image description

  • More info about Amazon MQ can be found here
  • Remember to delete the broker once finished if there is no other usage apart from demoing
  • Broker's configuration cannot be deleted
  • Broker's configuration can be used by multiple brokers

If you would like to support this effort to provide tutorials and demo code, please like us on Facebook or even ☕ Buy Me A Coffee

Discussion (1)

Collapse
oleg26dev profile image
Oleg26Dev

Thank you for the article.
What do you think: is it possible to develop one application
which will work with AWS MQ or RabbitMQ depending on config?