Queues

Create account queues, feed them from channels with rules, pause and delete them.

A queue collects copies of the messages published to the channels its rules match, for a worker of yours to consume over AMQP. The key needs the amqp-subscribe capability.

queues = Blackevin::Rest::Queues.new

queue = queues.upsert(name: 'inbox', max_length: 10_000)

queues.add_rule(queue.id, source_pattern: 'orders:*')

Addressed by id

Everything after creation takes the queue's id, not its name. The name is the physical queue on the broker and cannot change, so a 404 always means "no such queue" and never "someone renamed it".

queues.list                             # enabled queues
queues.list(all: true)                  # paused ones included

queues.update(queue.id, enabled: false) # pause; copies stop, the queue keeps what it has
queues.update(queue.id, max_length: nil) # remove the bound

queues.delete(queue.id)                 # and whatever is waiting in it

update sends only what it was given. max_length reaches the broker when the queue is next declared, not on a live one.

Rules

rule = queues.add_rule(queue.id, source_pattern: 'orders:*', filter: nil)

queues.rules(queue.id)                  # => [Blackevin::QueueRule]
queues.delete_rule(queue.id, rule.id)   # messages already enqueued stay

The plan's ceiling

upsert is keyed on the name, and only a new queue counts against the plan. An account at its limit can still edit what it has. Past the limit:

begin
  queues.upsert(name: 'one-too-many')
rescue Blackevin::Error => error
  error.quota?   # true
  error.reason   # 'queue_limit'
end

On this page