Crixa::Queue - A Crixa Queue
version 0.13
This class represents a single queue. With RabbitMQ, messages are published to exchanges, which then routes the message to one or more queues. You then consume those messages from the queue.
This class provides the following methods:
This method creates a new queue object. You should not call this method directly under normal circumstances. Instead, you should create a queue by calling the queue method on a Crixa::Channel or Crixa::Exchange object. However, you need to know what parameters the constructor accepts.
queue
name
The name of the queue. If none is provided then RabbitMQ will auto-generate a name for you.
passive => $bool
If this is true, then the constructor will throw an error unless the queue already exists.
This defaults to false.
durable => $bool
If this is true, then the queue will remain active across server restarts.
auto_delete => $bool
If this is true, then the queue will be deleted when there are no more consumers subscribed to it. The queue initially exists until at least one consumer subscribes.
exclusive => $bool
If this is true, then the queue is only accessible via the current connection and will be deleted when that connection closes.
This checks the queue for a message. This method does not block. It returns undef if there is no message ready. It accepts either a hash or hashref with the following keys:
undef
If this is true, then the message is not acknowledged as it is taken from the queue. You will need to explicitly acknowledge it using the ack method on the Crixa::Channel object from which the message came.
ack
If this is false, then the message is acknowledged immediately. Calling the ack method later with this message's delivery tag will be an error.
This defaults to true.
This method start consuming message via the AMQP consume API using the given callback. Internally, this uses the poll() system call to efficiently wait for messages to come in. You are strongly encouraged to use this over the wait_for_message() methods and instead of calling check_for_message() in a loop.
poll()
wait_for_message()
check_for_message()
The callback you provide will be passed a single optional argument. This argument is always a Crixa::Message object. However, if you specified a timeout (see below), then your callback may be called without any arguments at all.
Crixa::Message
The callback is expected to return true or false. If it returns true, Crixa will continue waiting for new messages. If it returns false, it will cancel the consumer and the consume() method will return.
consume()
Note that if you create an "auto-delete" queue, then it will be deleted after the last consumer it cancelled.
This method also accepts either a hash or hashref with the following keys after the callback:
timeout => $integer
This is an optional timeout for each internal call to the Net::AMQP::RabbitMQ->recv() method. If you specify this, then your callback will be called without any arguments.
Net::AMQP::RabbitMQ->recv()
consumer_tag => $string
A string identifying the consumer. If you don't provide one it will be generated automatically. This will be available from the Crixa::Message object passed to your callback, regardless of whether it is auto-generated or not.
no_local => $bool
If this is true, then the server will not send messages to the same connection as the one from which they were published.
no_ack => $bool
If this is true, then only this consumer may access the queue. If another consumer attempts to access the queue at the same time it will received an error.
This blocks until a message is ready. It always returns a single message.
This takes the same parameters as the check_for_message method.
check_for_message
This message takes a callback and blocks until the next message. It calls the callback with the message as its only argument and returns whatever the callback returns.
This takes the same parameters as the check_for_message method after the callback.
Returns the number of messages waiting in the queue.
This binds a queue to an exchange. It accepts either a hash or hashref with the following keys:
exchange
The name of the exchange to which the queue will be bound. This is required.
routing_key
An optional routing key for the binding. If none is given the queue name is used instead.
headers
An optional hashref used when binding to a headers matching exchange.
This hashref should contain the headers against which the queue is matching.
You can also specify an x-match key of either "any" or "all". If the value is "any" then the queue will receive a message when any of the headers in the message match those that the queue was bound with. if it is set to "all" then all headers in the message must match the binding.
x-match
This deletes the queue. It accepts either a hash or hashref with the following keys:
if_unused => $bool
If this is true, then the queue is only deleted if it has no consumers. Given the way that Crixa handles getting messages, this is irrelevant if you are only using Crixa to communicate with the queue.
if_empty => $bool
If this is true, then the queue is only deleted if it is empty.
Returns the queue name.
Returns the Crixa::Channel that this queue uses.
This returns the passive flag as passed to the constructor or set by a default.
This returns the durable flag as passed to the constructor or set by a default.
This returns the auto-delete flag as passed to the constructor or set by a default.
This returns the exclusive flag as passed to the constructor or set by a default.
Chris Prather <chris@prather.org>
Dave Rolsky <autarch@urth.org>
This software is copyright (c) 2012 - 2015 by Chris Prather.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Crixa, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Crixa
CPAN shell
perl -MCPAN -e shell install Crixa
For more information on module installation, please visit the detailed CPAN module installation guide.