Best practice setup for queues and topics and keys

50 views
Skip to first unread message

jgeiger

unread,
Nov 19, 2009, 11:22:10 AM11/19/09
to AMQP
I've set up a master/worker system using rabbit and amqp, and I'm
trying to determine if what I'm doing is the best way to be doing it.

My system consists of 4 parts databaser, scheduler, node and worker.
The scheduler finds jobs and distributes them to the workers via an
individual queue. The node listens to it's queue and launches workers
as requested by the scheduler, the databaser listens to it's queue,
and saves info into the DB. The worker listens to it's own queue and
sends status updates to the scheduler queue. I originally set up the
queues as:
(scheduler-queue, databaser-queue, node-queue)
and then 1 queue per worker
(worker-1-queue, worker-2-queue, etc.)

This is an issue since I was creating a lot of queues for the workers,
and while they were set to auto delete, it just didn't seem right (and
a few of them became orphaned)

I made a new change to replace the multiple worker queues with a topic
and key, so all the worker daemons listen to the same created queue,
but only pull messages off based on their key.
amq = ::MQ.new
amq.queue("worker").bind(@amq.topic('job'), :key =>
worker_key).subscribe { |msg| ... }

The part that is confusing me, is that in the scheduler when sending a
message to a worker I'm posting a message to the system, but marking
it with a topic and key, and not dropping it on a specific queue.
amq = ::MQ.new
amq.topic('job').publish(msg, :key => worker_key)

but, when sending a message to the node-queue, I'm sending it directly
to the queue.

amq.queue('node', :durable => true).publish(msg, :persistent => true)

I'm wondering if I would be better off just sending all messages to
topics and keys, even if I only have one thing listening to that
topic

amq.topic('node').publish(msg, :key => 'node')
amq.topic('databaser').publish(msg, :key => 'databaser')

or should I continue with publishing directly to the queue? Or is
there a better way altogether?

Thanks.

Chuck Remes

unread,
Nov 19, 2009, 12:18:21 PM11/19/09
to ruby...@googlegroups.com

On Nov 19, 2009, at 10:22 AM, jgeiger wrote:

>
> The part that is confusing me, is that in the scheduler when sending a
> message to a worker I'm posting a message to the system, but marking
> it with a topic and key, and not dropping it on a specific queue.
> amq = ::MQ.new
> amq.topic('job').publish(msg, :key => worker_key)
>
> but, when sending a message to the node-queue, I'm sending it directly
> to the queue.
>
> amq.queue('node', :durable => true).publish(msg, :persistent => true)
>
> I'm wondering if I would be better off just sending all messages to
> topics and keys, even if I only have one thing listening to that
> topic
>
> amq.topic('node').publish(msg, :key => 'node')
> amq.topic('databaser').publish(msg, :key => 'databaser')
>
> or should I continue with publishing directly to the queue? Or is
> there a better way altogether?

You never publish directly to a queue. The syntax you are using
(amq.queue(...)) is "syntatic sugar" for publishing to a direct
exchange. This sugar is added so you can build those compound
statements that read like a sentence.

It's the same as this:

amq = MQ.direct 'node'
amq.publish(msg)

cr

Reply all
Reply to author
Forward
0 new messages