DVELP-mobilearrow-flex-shortarrow-flexarrow arrowsbinocularschartcogsflex-icongeargithubglobeheadphoneslightnings linkedinlock newsletter-chartDvelp_Newsletterplantscalestarget triangle-icon twitter

RabbitMQ Fetching Remote Data

May 08, 2019

I want to tell you about rabbitmq and how to fetch data using this tool. Most readers know that DVELP BE side devs worked on Ruby on Rails, but how they can imagine Rails + Rabbit connection?

What’s the first option how we can imagine rails and rabbit connection? Funny one, but let’s move on.

What is that rabbit used for?!

Messaging enables software applications to connect and scale. Applications can connect to each other, as components of a larger application.

You may be thinking of data delivery, non-blocking operations or push notifications. Or you want to use publish / subscribe, asynchronous processing, or work queues. All these are patterns, and they form part of messaging.

RabbitMQ is a messaging broker. It gives your applications a common platform to send and receive messages, and your messages a safe place to live until received.

Real problem

Real problem

Ok, let’s check a real situation. We have list of applications which have to work as one system. How to get required data from the other app? A plain http request to a proper endpoint? That’s not the best option when you have to respond 1000s of unique requests per second. The possible way is messaging communication system. There are 2 the most popular ones:

Kafka vs. RabbitMQ

Due to languages support and free price started from $0/month for 1_000_000 messages, we choose to build our communication system based on RabbitMQ.

Basic structure

Fetcher listener

The basic structure consists of 2 parts: fetcher and listener. Let’s check integration steps:

  • Create a fetcher service which will send an external request to a rabbitmq queue and receive a result. It’s useful to use it as AR method. Ex: user.with_extended_data || user.auth_data
  • Create a listener service which will listen to get request data and respond with up to db data attributes. Start running as background sidekiq job to maintain connection between 2 apps.
  • Add CloudAMQP add-on to your listener heroku project and insert Bunny ENV credentials.

Now you know how to build your own communication system. Enjoy!



By using this website you agree to our cookie policy