Unfortunately, no Logic App connector can make the bridge to RabbitMQ, which makes this integration challenge a little bit more complicated. However, we have the ability to create an Azure Function by using the RabbitMQ trigger for Azure Functions to overcome this limitation.
The purpose of this POC is to receive a message in a RabbitMQ queue, and that event triggers an Azure Function, which fires a Logic App.
But first things first, to connect with RabbitMQ and even make that connection, we will use a Virtual Machine. There are other ways to work with RabbitMQ, and this is one of them.
So How to create a Virtual Machine to connect to RabbitMQ?
We are going to create one inside a resource group, and to make things correct, we are going to use specific names that you should use too. So first, we search for resource groups in the portal search bar, next click on Create, choose your subscription, and give it the name: azure-container-app-rg.
Next, inside the resource group, we are going to add a resource. In this case, it will be a virtual machine, but we are going to do it differently. Inside the resource group, click on Create.
Next, the Marketplace will open so that you can choose from a vast number of resources. But let’s be specific; search for “RabbitMQ packaged by Bitnami” and click on Create. A new window will open; click on Create.
Now this is how you should configure it:
- Use your subscription, and the resource group automatically will be the one we created since we are creating this resource directly in the resource group.
- Next, for the virtual machine name, use RabbitMQ
- Notice: on the picture below, we have an error there because we already have a VM created with that name, but this is to show you the process.
- Next, choose your region.
- As for available options, choose No infrastructure redundancy required
- Next, set the security type as standard
- And the image by default is already the one mentioned here. If not, choose that one.
- As for the Size, you can also choose the same as we did, it is not an expensive plan.
- Next, as for the Authentication type, choose the password option, and then set a username and a password. You will need it further in the process.
- Next, click on Review + Create, and after validation, click Create.
Wait for the deployment to be succeeded and click on Go to resource.
Once inside the resource, you can click on connect.
Next, click on SSH, and here, where it says: Run the example command below to connect to your VM. You are going to need only this: ssh username@000.111.000.111 (sample instruction).
- Of course, you will have your own IP address and the username you chose earlier when we configured the VM that you need to replace on the instruction above.
So now open the Microsoft Azure Command Prompt:
Write the ssh username@000.111.000.111 (sample instruction – this is not the username or IP address we use).
It will ask you:
Are you sure you want to continue connecting (yes/no/[fingerprint])?
And you should enter yes, and press Enter.
Next, it will request you to enter your password. This password is the one you defined when you created the virtual machine. While typing, it will not appear in the console, so do not worry. It is normal. After typing it, press enter.
Next, this is what you should see:
Now we can see that we are logged in to the virtual machine, where this VM is available with the Public IP we specified earlier in the process of starting the console. You also have some links for documentation from bitnami.
Now if we want to use RabbitMQ to produce messages or create queues and also to consume them, we need to expose port 5672 so that we can connect from the outside to this VM.
To do that, we need to run some commands, in this case, Azure CLI commands, and you can use PowerShell to do this, so let’s open port 5672.
Using Powershell, you will need to run this command:
az vm open-port --port 5672 --name rabbitmq >> --resource-group azure-container-app-rg
Here you specify the port to be opened (5672), the name of the VM (RabbitMQ), and also the resource group azure-container-app-rg.
If you do this without logging in, it will automatically ask you to log your credentials to the Azure Portal, and then you can rerun the command. If you are already logged in, just run the command.
While this command is getting executed, let’s also open the port for the Management UI, which is used to connect to RabbitMQ management capabilities. By default, this is exposed on port 15672, so it is the same command but with 15672 as the Port, and we also give priority to 1100; you can run this command on another PowerShell window.
az vm open-port --port 15672 --name rabbitmq >> --resource-group azure-container-app-rg --priority 1100
So once these two ports are open (5672/15672), we can then communicate with this VM, so let’s open the Browser and let’s connect to this particular port and copy the IP address on the virtual machine.
000.111.000.111:15672 (this example is to show that you need to use your IP followed by the: 15672 Port, and then you will have access to this RabbitMQ Management, but as you can see, you need a username and a password.
There is a default user and password created by bitnami, which we will use for this proof of concept.
To uncover the password, we can run this command on the still open:
cat ./bitnami_credentials
As you can see, after running that command, you are gifted with a username and a password that you can now use to access RabbitMQ Management.
Create the queues
Now with these credentials, log in to RabbitMQ Management, and this should be what you will see. You can explore it your own way, but for the sake of this proof of concept, we will focus on the Queues and the Admin panel.
This proof of concept aims to have an Azure Function that connects to RabbitMQ, and that triggers every time a message is published into a certain queue.
So, to achieve this, we first have to create two things:
- One queue
- One virtual host
Since the queue is living inside the virtual host, we first create a VHost. To do that, go into the Admin panel by clicking on Admin and then on Virtual Hosts.
By default, you already have one created, but the name of that virtual host is “/”, and this may create some conflicts in the long run, so let’s create a new one. It is just simple as adding the name you want and clicking on Add virtual host.
As we already have some virtual hosts created, let’s focus on the my-vhost-v2, and let’s move into the Queues panel and create a queue.
It is also as simple as choosing your virtual host first, so the queue will be hosted there, and you give a name to the new queue; next, you click Add queue.
As you can see, we already have some queues created, so let’s focus on the rabbit_mq_v3
>
So, what do we know?
We know that we have a queue named rabbit_mq_v3 hosted in a virtual host named my-vhost-v2.
And what can we do with it?
We can publish messages into that queue, and they will be there until a consumer consumes them out of that queue.
And how can we create a consumer?
We will have our Azure Function to take care of that.
But first, click on the queue you just created, and this is what you should see; no messages yet.
Now if you scroll down into the Publish message, you can publish a message into the queue.
You will see that the queue has one message published, which is waiting to be consumed.
Creating an Azure Function to consume RabbitMQ messages
Here comes the tricky part; how can we consume messages as soon as they enter the queue?
Azure Functions integrate with RabbitMQ via triggers and bindings. The Azure Functions RabbitMQ extension allows you to send and receive messages using the RabbitMQ API with Functions.
Because a Logic App connector doesn’t exist, we can create an Azure Function to act as the Logic App connector and bridge between RabbitMQ and the Logic App.
So, we pretend here to have an Azure Function that triggers as soon as a message enters the queue and then routes that message into a Logic App. There are a few tricks to make this work, but firstly we start with creating an Azure Function:
- In Visual Studio 2022, click on Create a new project.
- On the project template, choose Azure Functions.
- On the Configure your new project panel, give your Azure Function a name that makes sense to you and your coworkers; do not forget to start using proper names from day one! Choose the location of your Azure Function.
- Click next, and now you need to configure some fields:
- On the Function worker, choose .NET 6.0 (Long Term Support).
- On Function, select the RabbitMQ trigger.
- On the Connection string setting name, you can name the connection string as RabbitMQConnection.
- On the Queue name, add the name of the queue you created previously.
- Click on Create. After the project is created, use the following code you can find on GitHub:
Add these NuGet packages to the solution.
Next on the file local.settings.json is where you will store the connection string that enables you to connect with RabbitMQ and to do that, this is how the file should look like:
{ "IsEncrypted": false, "Values": { "AzureWebJobsStorage": "UseDevelopmentStorage=true", "RabbitMQConnection": "amqp://username:password@ip:port/vhostname" } }
amqp://user:acbdef@111.000.111.000:5672/my-vhost-v2 only the password and IP are fictitious in this example because you should have your own.
What does this Azure Function do?
This Azure Function is triggered by a RabbitMQ message in a specified queue. When a message arrives, the function is executed and performs the following steps:
- Logs an information message indicating that the function has been triggered.
- Prepares the payload for a request by creating an object with a “Message” property containing the content of the RabbitMQ message.
- Serializes the payload object into a JSON string.
- Creates an HTTP request with the JSON payload as the content and sets the content type to “application/json“.
- Defines the URL of a Logic App that will be the recipient of the HTTP request.
- Sends the HTTP request to the Logic App using the URL and payload.
- Check the response status of the request.
- If the request is successful (status code in the 2xx range), logs an information message indicating that the request was sent to the Logic App successfully.
- If the request fails (status code outside the 2xx range), logs an error message indicating the failure and includes the response’s status code.
In summary, this Azure Function acts as a bridge between a RabbitMQ queue and a Logic App. It receives messages from RabbitMQ, sends them as JSON payloads to a specified Logic App endpoint via an HTTP request, and logs the success or failure of the request.
Create the Logic App
To end this POC, we now need to prepare a Logic App Consumption.
- We named ours LA-ProcessMessageFromRabbitMQ-POC, and as for the trigger, choose When a HTTP request is received.
- Save the Logic App and copy the URL generated into your Azure Function.
- After this step, you can add the necessary business logic you need. In this POC, we are just getting the message.
Test the solution
Before we test our solution, we first need to finish configuring and publishing our Azure Function.
- After you save the Logic App, go to your Azure Function and set the correct URL on it (this should be changed to use a configuration instead)
// Set the Logic App endpoint URL
var logicAppUrl = “your-logic-app-uri“;
- Now that you set the URL for the Logic App inside your Azure Function, you can go ahead and publish it.
After having the Azure Function published, go into the Function App in the Azure Portal and:
- Choose the Azure Function you just created.
- Next, go to Configuration – + New application setting – On the name, give the same name as in the Azure Function – RabbitMQConnection, and as for the value, use the same connection string that is inside the local.settings.json file.
- Next, click Ok and click Save.
Now all that we have left is to test it!
- So go into the RabbitMQ queue and publish a message.
- As you can see, we now have a consumer connected to this queue. So, what we need to do next is to publish the message.
Now, in the App Insights logs, you can see that a message has been processed, the content of the message, and that it was sent into the Logic App successfully.
<
Now on the Logic App side, we can check our latest run, where we received the same message. Now, what you do with those messages is up to you. You can redirect them to another service, etc.
We hope you have enjoyed this POC as much as we did, and we will see you at the next one!
Big thanks to my team member Luís Rigueira for helping me realize and implement this idea.
The goal of this new series is to find common problems that people are facing with Logic Apps, either on Stack Overflow, Logic App forums, Azure Logic Apps Microsoft Q&A, or any other source – feel free to provide ideas/problems you would like to be addressed – and provide a solution or solutions to that problem. At least, I will add my point of view to address those issues. Of course, there may be other solutions; feel free to comment if that’s the case.
Turbo360 is an enterprise-grade cloud management platform for your Azure environment, and it comes with a free trial.