Tuesday, November 28, 2023

#997 - OIC - Integration with RabbitMQ on CloudAMQP

 


CloudAMQP provides managed RabbitMQ clusters on the cloud. It is quite popular, so it was only a matter of time before I got the question - How can I use OIC to integrate with RabbitMQ. Never one to dodge a challenge, I began by subscribing to the free version of RabbitMQ - Little Lemur.

Setting up the CloudAMQP account and RabbitMQ itself is very simple, I just needed to note the following details from the setup screens - the User, vHost and Password provided. I will need these later on when constructing the REST requests to RabbitMQ in Postman.


From the CloudAMQP homepage - I  click on the RabbitMQ Manager button to create my Queue - I provide a name - NiallCQueue - and just accept all the default settings.


A very simple task - my Queue is set up, now to the api docs to check out how to write to and read from the queue -


  Here is the link.

Next step is Postman, to try out the RabbitMQ apis - I begin with the most simple request - to retrieve the queue information -


I copy the relevant curl command from the RabbitMQ api docs and paste into Postman - 
Note that the first part of the url is user:password. You can get rid of this by setting up Basic Authorization with the same user/password in Postman.

Next request is to put a message on the queue -


Here I use Basic Auth, so no username/password in the url.

Let's look at the payload - 
routing_key - set to the name of the queue
payload - yes, the payload I want to write to the queue
payload_encoding - I left this as "string". 
From the docs - The payload_encoding key should be either "string" (in which case the payload will be taken to be the UTF-8 encoding of the payload field) or "base64" (in which case the payload field is taken to be base64 encoded).

properties - I left empty, to begin with.

The routed = true response tells me the message has been successfully sent to at least one queue.

Next api is the GET - 

Note the request payload - 

count - the max number of messages to retrieve from the queue.

encoding - set to auto

from the docs - encoding must be either "auto" (in which case the payload will be returned as a string if it is valid UTF-8, and base64 encoded otherwise), or "base64" (in which case the payload will always be base64 encoded).

ackmode - ack_requeue_false 

from the docs - ackmode determines whether the messages will be removed from the queue. If ackmode is ack_requeue_true or reject_requeue_true they will be requeued - if ackmode is ack_requeue_false or reject_requeue_false they will be removed.





All is working in Postman, so now on to OIC - 

Step 1 - Create the Connection

Here we use the OIC REST adapter -


Step 2 - Create a Scheduled Integration







































Here is the configuration of the REST invoke - 


























I use the request and response payloads from my Postman test as the request and response JSON samples.


 
























The For-Each configuration - 


The Logger action just logs the payload - 

Now to testing the integration - for this I have put 6 messages in the queue -



I run the integration and check out the activity stream - 


I check out one of the log actions - 




 


No comments: