ROR Application Development Tips

I'm Ruby on Rails developer. I love to share my experience, technical knowledge. I work at Crypex Technologies which is developing applications in ROR for more than a decade.

RabbitMQ with Ruby on Rails in 2018 for Web Application Development

An Introduction to RabbitMQ:

RabbitMQ is a message broker software where applications connect to the queue and transfer a message onto it.

When one application server sends the request to another application server, RabbitMQ works as a queue manager where requests handled and served one by one.

Message transferring is done from one application to another through RabbitMQ. RabbitMQ uses the standard Advanced Message Queuing Protocol (AMQP) to keep message request in queues and serve easily. A message may contain any information like simple text transfer or task that need to process on another server.

This RabbitMQ software saves messages in the queue and keep in a queue until receiving application get connected and start processing the messages.

 

Why should we use RabbitMQ with Ruby on Rails?

Message broker works on the producer, broker and consumer logic. Message broker server allows consumer and producer server to respond request fast instead of use resources heavily at one time. Message broker use to optimize load on server and provide services until application executes the task on requested server.Requested server can be any third party application which performs the task.

 

Queued messages will also use to send the messages or task to multiple recipient from consumption that leads to the load balancing on the producer and consumer server.

 

Let take example of rails server and bitcoin exchange server (bitcoind) for btc transaction working.

 

I have rails server running as producer and bitcoind server as consumer.

 

Rails server send multiple request to bitcoind server continuously.There may be chances to slow down bitcoind because of multiple requests send to bitcoind server to process task.

 

In that case, RabbitMQ can fulfill the role of load balancing and messages passing by keeping the request coming from rails server in queue and serve request one by one to bitcoind server.

 

Bitcoind server will take task from queue and start processing.

 

AMQP role in RabbitMQ:

 

AMQP store and forward messages to consumers, like same as SMTP protocol use to deliver mail to mailboxes.Messages starts from producer application to the exchanges that help to redirect in queues.Lastly queues deliver task to consumer application.Its now consumer server responsibility to take the messages from queues to process as required.

 

A virtual channel is use to establish the connection between publishing messages from queue. All process exchanges done over the channels.

 

How to use RabbitMQ in Rails application?

Using Bunny ruby RabbitMQ client, we can integrate RabbitMq with rails application.

 

There are some gems available to start with RabbitMQ in ruby like

gem “bunny”

 

Bunny help rails application to interoperate with consumer application, it can be built in any technologies irrespective of the size and complexity of an application. Also, add amqp gem in rails Gemfile to use AMQP protocol services

gem ‘amqp’

 

RabbitMQ installation commands in Ubuntu:

 

1] Step 1: Update system

sudo apt-get update

 

2] Step 2: Install Erlang

RabbitMQ is written in Erlang, you need to install Erlang before you can use it:

 

a] wget http://packages.erlang-solutions.com/site/esl/esl-erlang/FLAVOUR_1_general/esl-erlang_20.1-1~ubuntu~xenial_amd64.deb

b] sudo dpkg -i esl-erlang_20.1-1\~ubuntu\~xenial_amd64.deb

 

3] Step 3: Install RabbitMQ

sudo apt-get install rabbitmq-server

 

4] Step 4: Start the Server:

sudo systemctl start rabbitmq-server.service

sudo systemctl enable rabbitmq-server.service

 

Thus if you are looking for web development services which are faster, reliable, redundant and scalable then you can definitely opt for Ruby on Rails RabbitMQ.