DEV Community

Cover image for RabbitMQ Basics
CJ
CJ

Posted on • Originally published at chuanjin.me

2 2

RabbitMQ Basics

We need to prepare to scale up our web apps and do the time consuming jobs asynchronously in a stable way. Queue is a good tool to fulfill this requirement.

RabbitMQ fits our needs after investigation, so we try to add it into our apps.

Some terms need to mention:

producer: A program that sends messages

consumer: A program that mostly waits to receive messages.

queue: A buffer that stores messages. It is like a mailbox. Although messages flow through RabbitMQ and your applications, they can be stored only inside a queue. A queue can store as many messages as you like ‒ it's essentially an infinite buffer. Many producers can send messages that go to one queue, many consumers can try to receive data from one queue.
In RabbitMQ a message can never be sent directly to the queue, it always needs to go through an exchange.

exchange: It receives messages from producers and it pushes them to queues.

exchange types: direct, topic, headers and fanout.

Note:

  • Declare a queue to make sure it exists before using it.

  • If we send a message to non-existing location, RabbitMQ will just trash the message.

  • Before exiting the program we need to make sure the network buffers were flushed and our message was actually delivered to RabbitMQ. We can do it by gently closing the connection.

It is highly recommended to read through the official tutorial

Here is an example making use of the routing example and also enable fair dispatch for multiple workers.


Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more