POV
POV

Reputation: 12005

Should I create some exchanges Rabbit MQ?

My use case is following: I have several users, that subscribed on countries, other words, one user can be related to some countries.

So, producer sends message for country USA, it means that subscribed users on USA should recieve this message. Like a fanout type.

I was thinking about architecture of transport messages in Rabbit MQ broker.

So, I think it is ugly way to create exchanges equal number of countries.

Instead that I suppose to place one exchange with name country binded with some queues, one queue for one country.

Then on client side I determine on which queues users subscribed (Countries).

A continuation:

What if there are cities assigned to countries, and user also subscribes on cities of country?

Should I create another exchange cities and listen messages from queue? Can I send message from country exchange to city exchange directly?

Scheme is fr one country and some relative cities:

Producer -> CountryExhange(USA) -> 
CityExchange(Washington) -> Queue (Washington) -> 
Consumes (USA, Washington)

Upvotes: 0

Views: 538

Answers (1)

theMayer
theMayer

Reputation: 16167

Generally, message routing is dependent upon the type of message being processed. So, if each country has its own message type, then by all means set up one queue per country. Otherwise, let country-specific logic be dealt with by message consumers.

Edit:

The question asks whether additional exchanges should be created. It should be noted that the job of an exchange is to route each message published to one or more queues. Standard exchange types are direct, topic, and fanout. These exchanges exist by default in a newly-configured RabbitMQ server. Therefore, unless an additional exchange type is desired, there are very few cases where adding another exchange makes any sense.

Upvotes: 1

Related Questions