NAME

AnyMQ::Queue - AnyMQ Message Queue

SYNOPSIS

my $channel = AnyMQ->topic('Foo');
my $client = AnyMQ->new_listener($channel);

$client->poll_once(sub {
    my @messages = @_;
    # ...
});

$client->poll(sub {
    my @messages = @_;
    # ...
});

DESCRIPTION

An AnyMQ::Queue instance is a queue, each message put into the queue can be consumed exactly once. It's used as the client (or the subscriber in terms of pub/sub) in AnyMQ. An AnyMQ::Queue can subscribe to multiple AnyMQ::Topic.

METHODS

subscribe($topic)

Subscribe to a AnyMQ::Topic object.

poll($code_ref)

This is the event-driven poll mechanism, which accepts a callback. Messages are streamed to $code_ref passed in.

unpoll

Cancels a running "poll", which will result in "on_timeout" being called.

poll_once($code_ref, $timeout)

This method returns all messages since the last poll to $code_ref. It blocks for $timeout seconds if there's currently no messages available.

destroyed(BOOL)

Marking the current queue as destroyed or not.

timeout($seconds)

Timeout value for this queue. Default is 55.

on_error(sub { my ($queue, $error, @msg) = @_; ... })

Sets the error handler invoked when poll or poll_once callbacks fail. By default the queue is marked as destroyed. If you register this error handler, you should call $queue->destroyed(1) should you wish to mark the queue as destroyed and reclaim resources.

Note that for queues that are currently poll'ed, you may unset the persistent attribute to avoid the queue from being destroyed, and can be used for further poll or poll_once calls. In this case, on_timeout will be triggered if poll or poll_once is not called after $self->timeout seconds.

on_timeout(sub { my ($queue, $error) = @_; ... })

If a queue is not currently polled, this callback will be triggered after $self->timeout seconds. The default behaviour is marking the queue as destroyed.

append(@messages)

Append messages directly to the queue. You probably want to use publish method of AnyMQ::Topic

SEE ALSO

AnyMQ AnyMQ::Topic