I have an event (say activity) which may be active or not at a given time. I'm looking for a way to use RabbitMQ to figure if the event is active or not. I know the use case of RabbitMQ is pub/sub. How do I use RabbitMQ to be able to say if an event is currently active or not. More like a variable which is updated in real-time. I know I can achieve this using Firebase Database; but is there any way I can do it using RabbitMQ? If not RabbitMQ, are there any other suggestions? I cannot use mySQL etc. because that will not be real-time.
-
I'm not sure I understand the question. RabbitMQ is a message broker - it generally is not an application state container (are you looking for a database?) – theMayer Aug 30 '18 at 13:52
-
What is the requirement behind this design choice? What are you trying to achieve? – noxdafox Sep 08 '18 at 09:35
-
@nodafox I want users (subscribers) to know when an event is live in real time. So one way is to send status every 1 second. Is there any other? – Alec Smart Sep 08 '18 at 15:32
-
@AlecSmart can you please define what do you mean by Real Time? Wouldn't a key-value storage solution such as Redis be enough? – noxdafox Sep 10 '18 at 13:10
-
Key value store is fine. But how do I, in real-time, on the front-end (say JS), know whether the value is set or not? – Alec Smart Sep 11 '18 at 07:06
-
You are not clarifying what you mean by real time. What are the time constraints? What type of architecture are you designing? Hard RT, RT or Soft RT? – noxdafox Sep 11 '18 at 07:24
-
Like 1-2 seconds. I'm not very well versed with the terms you're asking for so I'll look them up. Sorry. – Alec Smart Sep 11 '18 at 07:37
-
Wikipedia has a good explanation for them. – noxdafox Sep 11 '18 at 10:23
-
Although you could utilise the Pub/Sub pattern here, i believe that RabbitMQ might not be the most convenient broker to use. Take for example MQTT, with any MQTT broker you could just split your state onto different topics under MQTT's topic tree with a RETAIN flag on each message and thus subscribing to a topic would instantly give you the state of that activity. Example: /activities/1/state /activities/2/state /activities/3/state and subscribe to /activities/+/state to handle all at once, or sub to activities/X/state on demand to get each state. – slysterous Sep 13 '19 at 07:16
2 Answers
RabbitMQ is a message broker, it is not suited for representing state across distributed systems.
For this purpose, I'd rather recommend any storage solution which provides transactions (SQL or NoSQL) as what you really want to ensure is the data is set atomically.
Solutions such as Redis, MongoDB, PostgreSQL are all providing what you need. Cloud providers nowadays offer similar solutions as managed services.
If latency when accessing the state is critical within your application (if this is what you mean with "Real Time"), then you will need to carefully consider your architecture. As the state will be stored in a remote location (be it RabbitMQ, Redis or whatever else), the network latency and it's (un)reliability will be the most important factor.

- 14,439
- 4
- 33
- 45
The one way this can be done using RabbitMQ - although it's weird - is using expiring/autoDelete queues as records.
You can assert a queue with expires
option meaning it is deleted after x milliseconds of disuse. Then you can simply check if the queue exists. If it exists event is active if it doesn't event is not active.
If your event active/inactive state is more dynamic you could also create queues with just autoDelete
option and hook some fake consumer to them. Queue will exist as long as the consumer will exists so to remove the queue simply stop the consumer.
I hope the answer makes sense.

- 3,317
- 18
- 31