|
NAMEMojo::RabbitMQ::Client::Channel - handles all channel related methodsSYNOPSISuse Mojo::RabbitMQ::Client::Channel; my $channel = Mojo::RabbitMQ::Client::Channel->new(); $channel->catch(sub { warn "Some channel error occurred: " . $_[1] }); $channel->on( open => sub { my ($channel) = @_; ... } ); $channel->on(close => sub { warn "Channel closed" }); $client->open_channel($channel); DESCRIPTIONMojo::RabbitMQ::Client::Channel allows one to call all channel related methods.EVENTSMojo::RabbitMQ::Client::Channel inherits all events from Mojo::EventEmitter and can emit the following new ones.open$channel->on(open => sub { my ($channel) = @_; ... }); Emitted when channel receives Open-Ok. close$channel->on(close=> sub { my ($channel, $frame) = @_; ... }); Emitted when channel gets closed, $frame contains close reason. ATTRIBUTESMojo::RabbitMQ::Client::Channel has following attributes.idmy $id = $channel->id; $channel->id(20810); If not set, Mojo::RabbitMQ::Client sets it to next free number when channel is opened. is_open$channel->is_open ? "Channel is open" : "Channel is closed"; is_active$channel->is_active ? "Channel is active" : "Channel is not active"; This can be modified on reception of Channel-Flow. clientmy $client = $channel->client; $channel->client($client); METHODSMojo::RabbitMQ::Client::Channel inherits all methods from Mojo::EventEmitter and implements the following new ones.close$channel->close; Cancels all consumers and closes channel afterwards. declare_exchangemy $exchange = $channel->declare_exchange( exchange => 'mojo', type => 'fanout', durable => 1, ... )->deliver; Verify exchange exists, create if needed. This method creates an exchange if it does not already exist, and if the exchange exists, verifies that it is of the correct and expected class. Following arguments are accepted:
declare_exchange_pSame as declare_exchange but auto-delivers method and returns a Mojo::Promise object.$channel->declare_exchange_p( exchange => 'mojo', type => 'fanout', durable => 1, ... )->then(sub { say "Exchange declared..."; })->catch(sub { my $err = shift; warn "Exchange declaration error: $err"; })->wait; delete_exchange$channel->delete_exchange(exchange => 'mojo')->deliver; Delete an exchange. This method deletes an exchange. When an exchange is deleted all queue bindings on the exchange are cancelled. Following arguments are accepted:
delete_exchange_pSame as delete_exchange but auto-delivers method and returns a Mojo::Promise object.$channel->delete_exchange_p( exchange => 'mojo' )->then(sub { say "Exchange deleted..."; })->catch(sub { my $err = shift; warn "Exchange removal error: $err"; })->wait; declare_queuemy $queue = $channel->declare_queue(queue => 'mq', durable => 1)->deliver Declare queue, create if needed. This method creates or checks a queue. When creating a new queue the client can specify various properties that control the durability of the queue and its contents, and the level of sharing for the queue. Following arguments are accepted:
declare_queue_pSame as declare_queue but auto-delivers method and returns a Mojo::Promise object.$channel->declare_queue_p( queue => 'mq', durable => 1 )->then(sub { say "Queue declared..."; })->catch(sub { my $err = shift; warn "Queue declaration error: $err"; })->wait; bind_queue$channel->bind_queue( exchange => 'mojo', queue => 'mq', routing_key => '' )->deliver; Bind queue to an exchange. This method binds a queue to an exchange. Until a queue is bound it will not receive any messages. In a classic messaging model, store-and-forward queues are bound to a direct exchange and subscription queues are bound to a topic exchange. Following arguments are accepted:
bind_queue_pSame as bind_queue but auto-delivers method and returns a Mojo::Promise object.$channel->bind_queue_p( exchange => 'mojo', queue => 'mq', routing_key => '' )->then(sub { say "Queue bound..."; })->catch(sub { my $err = shift; warn "Queue binding error: $err"; })->wait; unbind_queue$channel->unbind_queue( exchange => 'mojo', queue => 'mq', routing_key => '' )->deliver; Unbind a queue from an exchange. This method unbinds a queue from an exchange. Following arguments are accepted:
unbind_queue_pSame as unbind_queue but auto-delivers method and returns a Mojo::Promise object.$channel->unbind_queue_p( exchange => 'mojo', queue => 'mq', routing_key => '' )->then(sub { say "Queue unbound..."; })->catch(sub { my $err = shift; warn "Queue unbinding error: $err"; })->wait; purge_queue$channel->purge_queue(queue => 'mq')->deliver; Purge a queue. This method removes all messages from a queue which are not awaiting acknowledgment. Following arguments are accepted:
purge_queue_pSame as purge_queue but auto-delivers method and returns a Mojo::Promise object.$channel->purge_queue_p( queue => 'mq', )->then(sub { say "Queue purged..."; })->catch(sub { my $err = shift; warn "Queue purging error: $err"; })->wait; delete_queue$channel->delete_queue(queue => 'mq', if_empty => 1)->deliver; Delete a queue. This method deletes a queue. When a queue is deleted any pending messages are sent to a dead-letter queue if this is defined in the server configuration, and all consumers on the queue are cancelled. Following arguments are accepted:
delete_queue_pSame as delete_queue but auto-delivers method and returns a Mojo::Promise object.$channel->delete_queue_p( queue => 'mq', if_empty => 1 )->then(sub { say "Queue removed..."; })->catch(sub { my $err = shift; warn "Queue removal error: $err"; })->wait; publishmy $message = $channel->publish( exchange => 'mojo', routing_key => 'mq', body => 'simple text body', ); $message->deliver(); Publish a message. This method publishes a message to a specific exchange. The message will be routed to queues as defined by the exchange configuration and distributed to any active consumers when the transaction, if any, is committed. Following arguments are accepted:
consumemy $consumer = $channel->consume(queue => 'mq'); $consumer->on(message => sub { ... }); $consumer->deliver; This method asks the server to start a "consumer", which is a transient request for messages from a specific queue. Consumers last as long as the channel they were declared on, or until the client cancels them. Following arguments are accepted:
cancel$channel->cancel(consumer_tag => 'amq.ctag....')->deliver; End a queue consumer. This method cancels a consumer. This does not affect already delivered messages, but it does mean the server will not send any more messages for that consumer. The client may receive an arbitrary number of messages in between sending the cancel method and receiving the cancel-ok reply. Following arguments are accepted:
getmy $get = $channel->get(queue => 'mq') $get->deliver; Direct access to a queue. This method provides a direct access to the messages in a queue using a synchronous dialogue that is designed for specific types of application where synchronous functionality is more important than performance. This is simple event emitter to which you have to subscribe. It can emit:
Following arguments are accepted:
ack$channel->ack(delivery_tag => 1); Acknowledge one or more messages. When sent by the client, this method acknowledges one or more messages delivered via the Deliver or Get-Ok methods. When sent by server, this method acknowledges one or more messages published with the Publish method on a channel in confirm mode. The acknowledgement can be for a single message or a set of messages up to and including a specific message. Following arguments are accepted:
qos$channel->qos(prefetch_count => 1)->deliver; Sets specified Quality of Service to channel, or entire connection. Accepts following arguments:
recover$channel->recover(requeue => 0)->deliver; Redeliver unacknowledged messages. This method asks the server to redeliver all unacknowledged messages on a specified channel. Zero or more messages may be redelivered.
reject$channel->reject(delivery_tag => 1, requeue => 0)->deliver; Reject an incoming message. This method allows a client to reject a message. It can be used to interrupt and cancel large incoming messages, or return untreatable messages to their original queue. Following arguments are accepted:
select_txWork with transactions.The Tx class allows publish and ack operations to be batched into atomic units of work. The intention is that all publish and ack requests issued within a transaction will complete successfully or none of them will. Servers SHOULD implement atomic transactions at least where all publish or ack requests affect a single queue. Transactions that cover multiple queues may be non-atomic, given that queues can be created and destroyed asynchronously, and such events do not form part of any transaction. Further, the behaviour of transactions with respect to the immediate and mandatory flags on Basic.Publish methods is not defined. $channel->select_tx()->deliver; Select standard transaction mode. This method sets the channel to use standard transactions. The client must use this method at least once on a channel before using the Commit or Rollback methods. commit_tx$channel->commit_tx()->deliver; Commit the current transaction. This method commits all message publications and acknowledgments performed in the current transaction. A new transaction starts immediately after a commit. rollback_tx$channel->rollback_tx()->deliver; Abandon the current transaction. This method abandons all message publications and acknowledgments performed in the current transaction. A new transaction starts immediately after a rollback. Note that unacked messages will not be automatically redelivered by rollback; if that is required an explicit recover call should be issued. SEE ALSOMojo::RabbitMQ::Client, Mojo::RabbitMQ::Client::Method, Net::AMQP::Protocol::v0_8COPYRIGHT AND LICENSECopyright (C) 2015-2017, Sebastian Podjasek and othersBased on AnyEvent::RabbitMQ - Copyright (C) 2010 Masahito Ikuta, maintained by "bobtfish@bobtfish.net" This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.
Visit the GSP FreeBSD Man Page Interface. |