Reputation: 109
I am building a message based web application that supposes to present stocks quotes in real time,
I chose RabbitMQ as my message bus, I have a single exchange that takes streams of quotes from several liquidity providers and route them to the corresponding queues according to the routing key. Then the quote is being parsed and displayed on the relevant widget on the screen.
This is the Exchange and queues structure -
| exchange | type | routing key | queue |
|------------------------------------------------------------------|
| quotes | topic | NASDAQ.MSFT.500 | Widget1Id |
| quotes | topic | NASDAQ.FB.1500 | Widget2Id |
| quotes | topic | S&P500.ABT.200 | Widget3Id |
| quotes | topic | S&P500.MMM.200 | Widget4Id |
| quotes | topic | S&P500.MMM.500 | Widget5Id |
So.. The problem starts when I want to change the routing key of queue Widget1Id to let's say S&P500.ACN.200
I have considered several options:
1. Delete Widget1Id queue and recreate is.
2. Unbind the queue and bind it again using the new routing key
(makes me always save the old routing key)
Which way will be the fastest?
Safest?
Will make me loose fewer data?
If you have any comments for the way that I have modeled the Queues and routing keys I will love to hear so.
Thanks Ahead
Upvotes: 1
Views: 1805
Reputation: 2137
Another option is to keep your Widget1Id
queue and bind it a second time to the exchange with the S&P500.ACN.200
routing key. This way, Widget1Id
will receive messages for both routing keys. When you are ready, you can remove the previous binding.
You won't loose messages already queued in Widget1Id
and you won't loose messages published between the moment you unbind/rebind or you recreate the queue.
This scenario is covered in Tutorial 4 in the RabbitMQ documentation if you want a more concrete example.
Upvotes: 1
Reputation: 2093
Both options you mention will result in loss of data for you. I would suggest that you either follow approach 2 (where you unbind and bind again). Another way you can do this is to create a new queue and bind that queue with the new routing key to the exchange and later delete the existing queue and its binding.
Upvotes: 0