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

Top comments (4)

Collapse
 
oleg26dev profile image
Oleg26Dev

Hi, I have tried to create a small test app working with AWS RabbitMQ. The problem is I cannot connect to tha AWS RabbitMQ, it writes: no any endpoints. The same app connects Ok to a docker RabbitMQ. My WAS RabbitMQ is public available.
What should I check ?

Collapse
 
fullstackcodr profile image
fullstackcodr • Edited

Hello @oleg26 and thanks for your comment!

Please ensure that the broker is created (some times it takes a while). You can check this from the status field in the console. The endpoints are listed after the creation process is finished.

Once the broker is created please pick one of the endpoints regarding your preferred protocol (openwire, amqp, stomp, mqttm wss).

Also please ensure that you give access to this broker from the security group (inbound rules).

You may want to have a look at the official documentation as well:
docs.aws.amazon.com/amazon-mq/late...

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?

Collapse
 
sbejjam profile image
Sudheer Bejjam

How to deploy consumer app using Kubernetes?