0

I want to define a queue such that all msgs coming to it is routed to different worker and at the same time shared specifically with one of the workers I guess a diagram can explain better

W(i) - Worker which recieves distinct msgs

W(sp) - is special worker which recieves all the msgs

Q - Queue

'---------------------------------------Q-------------------------

|--------------------------- |---------------------------- |
|--------------------------- |---------------------------- |
W1,W(sp)-------------W2,W(sp)-----------W3,W(sp)

As you can see W1,W2,W3,W4 are all distinct workers each receiving distinct msgs like a normal worker. Each will recieve one job from the queue

However each of the msgs should be shared with like an exchange W(sp). How can i achieve it. Is there some parameter which i can set so that W(sp) can always receive all the events from the queue

It will be great if you could help

EDIT 1

I found its a little tricky to understand the question ,here's another version

I want to share jobs from queue in round robin so that a job is given only once to a consumer as i want to do parallel processing of job, and at the same time i want a special consumer which will also get all the jobs from queue.

Eg:

counsumer - C1,C2,C3,C4

special consumer - Csp

queue - Q

Each job in Q should be broadcasted to one of C1,C2,C3,C4 and shared with Csp . Thus a job from Q is shared between Csp and one of C(i). With this i will we able to parallely process jobs in C1,C2,C3,C4 etc and at the same time validate each of the jobs in Q with my consumer Csp

prajnavantha
  • 1,111
  • 13
  • 17

2 Answers2

0

As far as I understand you need a Topic Exchange. Set up different routing keys for messages. And let Workers pick what they are interested in. For example, the worker that needs to get all messages can create a queue and bind it to the exchange with "#" (hash) binding key.

We created three bindings: Q1 is bound with binding key ".orange." and Q2 with "..rabbit" and "lazy.#".

These bindings can be summarised as:

Q1 is interested in all the orange animals.
Q2 wants to hear everything about rabbits, and everything about lazy animals.

A message with a routing key set to "quick.orange.rabbit" will be delivered to both queues. Message "lazy.orange.elephant" also will go to both of them. On the other hand "quick.orange.fox" will only go to the first queue, and "lazy.brown.fox" only to the second. "lazy.pink.rabbit" will be delivered to the second queue only once, even though it matches two bindings. "quick.brown.fox" doesn't match any binding so it will be discarded.

UPDATED:

Take a look at the repositories that this guy has: https://github.com/simonmacmullen

I guess you will be interested in this one: https://github.com/simonmacmullen/random-exchange

This exchange type is for load-balancing among consumers.
Vor
  • 33,215
  • 43
  • 135
  • 193
  • Thnks for the reply Vor, however i see a problem. Using topic broadcasts same msg to all consumers connected to that queue. I want to share jobs in round robin so that a job is given only once to a consumer as i want to do parallel processing of job, and at the same time i want a special consumer which will also get all the jobs from queue. Eg: counsumer - C1,C2,C3,C4 special consumer - Csp queue - Q Each job should be broadcasted to one of C1,C2,C3,C4 and Csp Thus msg is shared betweenn Csp and one of C(i) – prajnavantha Feb 19 '15 at 19:20
0

Thanks vor for help but i guess that didnt help, however i did solve the problem. It was just about givin the queue a name , so that all the consumers connected to queue will get the work shared in round robin. Heres an example

counsumer - C1,C2,C3,C4

special consumer - Csp

queue - Q

I should create the connection as follows

Emit:

channel.exchange_declare(exchange='logs2',type='fanout')

For recieving events from C(i) i should bind my queue to exchange with a queue name

channel.queue_bind(exchange='logs2',queue='hello')

Any Amount of Consumers connected to this queue will recieve one job at a time in round robin

For recieving events from exchange with Csp

channel.queue_bind(exchange='logs2',queue='special')

This special queue will recieve all the events from the exchange as this is connected to exchange logs2

prajnavantha
  • 1,111
  • 13
  • 17