V
V
VladimirKrasnov2021-02-16 10:59:20
Redis
VladimirKrasnov, 2021-02-16 10:59:20

Should I use Redis as a message broker?

Hi, got to learning about message brokers. I got acquainted \ practiced with RabbitMQ and kafk and found out that Redis can also be a message broker. Should I use it as a broker? Are there any packages for php\laravel?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2021-02-16
@VladimirKrasnov

Redis has two features related to "messages":

  1. Pub/Sub - Publisher/Subscriber pattern - message delivered to all subscribers as soon as it is sent
  2. Lists - Lists are just a data structure in memory. New tasks are added to the "tail", workers sort tasks from the "head".

Redis Pub/Sub is (almost) real-time message delivery, not a message queue . They missed the message, did not accept it, subscribed later - they are not aware of what happened. Laravel, of course, works with Redis PubSub.
Redis Lists can be used as storage for task queues - with a blocking read command (eg BLPOP) it's more like *.MessageQueue. See queues in Laravel . The Redis BLPOP command is blocking, it waits for a new element to appear in the list and exclusively grabs it. It is possible to hang several "worker" processes to one Redis. They will hang and wait for the tasks to appear. Some of them will receive the next task and will process it.

I
Ilya, 2021-02-17
@sarapinit

Should I use it as a broker?

I would consider 2 options:
1) Pub / Sub (it was already written about above) - it does not particularly guarantee anything and does not store messages, if at the moment the subscriber failed to receive it, then it will never succeed.
2) Redis Streams (starting from version 5.0) is already closer to message brokers, but not a full-fledged one, but rather a set of commands from which you can assemble your message broker. Some persistence is declared due to replication between replicas, data dumps to disk and logging of all write operations. It is not clear how reliable it is, I have not heard of anyone using Redis as a reliable data store.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question