Thursday, April 7, 2016

RabbitMQ Client Server using Go

RabbitMQ is an open source message broker software that implements Advanced Message Queue Protocol(AMQP). In this demo I will implement message queuing client server architecture using GO.
First we need to install a GO library which can communicate with RabbitMQ using AMQP protocol. AMQP is one of the mostly used GO client for AMQP.  First, I will install AMQP library in my local machine.
Next implement get queue function. We could directly create queue and publish the messages. But for re-usability purposes I wrote below function. The getQueue function returns three arguments. First one is the actual connection between RabbitMQ and application. Channel is the communication path between RabbitMQ and application. Last one is the actual queue. If an error occurred you can see the logs using handleError helper function. You can check documentation for QueueDeclare function from here.
Next we need to publish messages to above queue.
Our main function should be like below.
Run the main.go file in your solution folder.
In the RabbitMQ console you will be able to see an output similar to below screenshot.
Next we will implement queue subscribe client.
Now we need to change main function accordingly.
Run main.go file and you will see following output in RabbitMQ console.

No comments:

Post a Comment