Mojo::...Channel(3pm)
okay so bestie, welcome to the Mojo::RabbitMQ::Client::Channel(3pm) manual page from User Contributed Perl Documentation โ it's giving โchannel methods onlyโ main character energy, and we're gonna read it together ๐
๐ธ NAME ๐ธ
Mojo::RabbitMQ::Client::Channel โ handles all channel related methods. That's it, that's the whole assignment: every channel-related method lives here, and she's ready to slay ๐
โจ SYNOPSIS โจ
use 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);
๐ DESCRIPTION ๐
Mojo::RabbitMQ::Client::Channel allows one to call all channel related methods. Lowkey the whole point: you want channel stuff, you call channel stuff. No cap ๐ซถ
๐ฆ EVENTS ๐ฆ
Mojo::RabbitMQ::Client::Channel inherits all events from Mojo::EventEmitter and can emit the following new ones. So yes, bestie, she's got the family traits plus her own signature moments โจ
๐ open ๐
$channel->on(open => sub {
my ($channel) = @_;
...
});
Emitted when channel receives Open-Ok. That's the little โwe're so onโ signal, and the vibe check is passed ๐
๐ close ๐
$channel->on(close=> sub {
my ($channel, $frame) = @_;
...
});
Emitted when channel gets closed, $frame contains close reason. So if things go sideways, the $frame is literally carrying the receipts ๐ญ
๐ ATTRIBUTES ๐
Mojo::RabbitMQ::Client::Channel has following attributes. These are the little properties she carries around, and yes they're all iconic in their own way ๐
๐ธ id ๐ธ
my $id = $channel->id;
$channel->id(20810);
If not set, Mojo::RabbitMQ::Client sets it to next free number when channel is opened. So she gets her little number assigned automatically, like a deli ticket but cuter ๐๏ธ
โญ is_open โญ
$channel->is_open ? "Channel is open" : "Channel is closed";
This is the โare we open or are we closedโ check, and it returns the matching string. Simple, clean, no drama ๐
๐ฅ is_active ๐ฅ
$channel->is_active ? "Channel is active" : "Channel is not active";
This can be modified on reception of Channel-Flow. So yeah, active status can change when the server sends that flow energy ๐
๐ฆ client ๐ฆ
my $client = $channel->client;
$channel->client($client);
The client attribute, right there for you to get and set. Teamwork, bestie ๐ซถ
๐ METHODS ๐
Mojo::RabbitMQ::Client::Channel inherits all methods from Mojo::EventEmitter and implements the following new ones. So she's got inherited skills plus her own custom slay โจ
๐ close ๐
$channel->close;
Cancels all consumers and closes channel afterwards. So it's a clean shutdown vibe: consumers get cancelled, then the channel closes. Periodt ๐
๐ declare_exchange ๐
my $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. Very โlet me check your vibe and your paperworkโ of her, honestly ๐ต๏ธโ๏ธ
Following arguments are accepted:
๐ exchange ๐
Unique exchange name
๐ type ๐
Each exchange belongs to one of a set of exchange types implemented by the server. The exchange types define the functionality of the exchange - i.e. how messages are routed through it. It is not valid or meaningful to attempt to change the type of an existing exchange.
๐ passive ๐
If set, the server will reply with Declare-Ok if the exchange already exists with the same name, and raise an error if not. The client can use this to check whether an exchange exists without modifying the server state. When set, all other method fields except name and no-wait are ignored. A declare with both passive and no-wait has no effect. Arguments are compared for semantic equivalence.
๐ durable ๐
If set when creating a new exchange, the exchange will be marked as durable. Durable exchanges remain active when a server restarts. Non-durable exchanges (transient exchanges) are purged if/when a server restarts.
๐ auto_delete ๐
If set, the exchange is deleted when all queues have finished using it.
๐ internal ๐
If set, the exchange may not be used directly by publishers, but only when bound to other exchanges. Internal exchanges are used to construct wiring that is not visible to applications.
๐ declare_exchange_p ๐
Same 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. Like cleaning out the group chat, but for bindings ๐
Following arguments are accepted:
๐ exchange ๐
Exchange name.
๐ if_unused ๐
If set, the server will only delete the exchange if it has no queue bindings. If the exchange has queue bindings the server does not delete it but raises a channel exception instead.
๐ delete_exchange_p ๐
Same 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_queue ๐ฆ
my $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. Very โnew queue, who disโ energy ๐
Following arguments are accepted:
๐ queue ๐
The queue name MAY be empty, in which case the server MUST create a new queue with a unique generated name and return this to the client in the Declare-Ok method.
๐ passive ๐
If set, the server will reply with Declare-Ok if the queue already exists with the same name, and raise an error if not. The client can use this to check whether a queue exists without modifying the server state. When set, all other method fields except name and no-wait are ignored. A declare with both passive and no-wait has no effect. Arguments are compared for semantic equivalence.
๐ durable ๐
If set when creating a new queue, the queue will be marked as durable. Durable queues remain active when a server restarts. Non-durable queues (transient queues) are purged if/when a server restarts. Note that durable queues do not necessarily hold persistent messages, although it does not make sense to send persistent messages to a transient queue.
๐ exclusive ๐
Exclusive queues may only be accessed by the current connection, and are deleted when that connection closes. Passive declaration of an exclusive queue by other connections are not allowed.
๐ auto_delete ๐
If set, the queue is deleted when all consumers have finished using it. The last consumer can be cancelled either explicitly or because its channel is closed. If there was no consumer ever on the queue, it won't be deleted. Applications can explicitly delete auto-delete queues using the Delete method as normal.
๐ declare_queue_p ๐
Same 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. It's giving โlink up, bestieโ ๐ฅ
Following arguments are accepted:
๐ queue ๐
Specifies the name of the queue to bind.
๐ exchange ๐
Name of the exchange to bind to.
๐ routing_key ๐
Specifies the routing key for the binding. The routing key is used for routing messages depending on the exchange configuration. Not all exchanges use a routing key - refer to the specific exchange documentation. If the queue name is empty, the server uses the last queue declared on the channel. If the routing key is also empty, the server uses this queue name for the routing key as well. If the queue name is provided but the routing key is empty, the server does the binding with that empty routing key. The meaning of empty routing keys depends on the exchange implementation.
๐ bind_queue_p ๐
Same 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. Sometimes you gotta unlink for your peace of mind, and that's valid ๐ฆ
Following arguments are accepted:
๐ queue ๐
Specifies the name of the queue to unbind.
๐ exchange ๐
The name of the exchange to unbind from.
๐ routing_key ๐
Specifies the routing key of the binding to unbind.
๐ unbind_queue_p ๐
Same 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. It's the โclear the draftsโ button, but make it broker-side โจ
Following arguments are accepted:
๐ queue ๐
Specifies the name of the queue to purge.
๐ purge_queue_p ๐
Same 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. It's a whole cleanup arc, honestly ๐ญ
Following arguments are accepted:
๐ queue ๐
Specifies the name of the queue to delete.
๐ if_unused ๐
If set, the server will only delete the queue if it has no consumers. If the queue has consumers the server does does not delete it but raises a channel exception instead.
๐ if_empty ๐
If set, the server will only delete the queue if it has no messages.
๐ delete_queue_p ๐
Same 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;
publish
my $message = $channel->publish(
exchange => 'mojo',
routing_key => 'mq',
body => 'simple text body',
);
$message->deliver();
Publish a message. ๐
This one yeets a message to a specific exchange. The message gets routed to queues as defined by the exchange configuration, and then distributed to any active consumers when the transaction (if there even is one) is committed. It's giving "put it in the mailbox and hope the routing slays."
Following arguments are accepted:
exchange
Specifies the name of the exchange to publish to. The exchange name can be empty, meaning the default exchange. โ ๏ธ But bestie, listen โ if the exchange name is specified and that exchange doesn't exist, the server will raise a channel exception. So like, know your exchange names, okay?
routing_key
Specifies the routing key for the message. The routing key is what's used for routing messages depending on the exchange configuration. It's literally the address on the envelope.
mandatory
This flag tells the server how to react if the message can't be routed to a queue. If this flag is set, the server will return an unroutable message with a Return method. If this flag is zero, the server silently drops the message ๐ (no cap, just gone).
All rejections are emitted as reject event.
$message->on(reject => sub {
my $message = shift;
my $frame = shift;
my $method_frame = $frame->method_frame;
my $reply_code = $method_frame->reply_code;
my $reply_text = $method_frame->reply_text;
});
immediate
This flag tells the server how to react if the message can't be routed to a queue consumer immediately. If this flag is set, the server will return an undeliverable message with a Return method. If this flag is zero, the server will queue the message โ but with no guarantee that it will ever be consumed. ๐ Like leaving a text on read forever.
As said above, all rejections are emitted as reject event.
$message->on(reject => sub { ... });
consume
my $consumer = $channel->consume(queue => 'mq');
$consumer->on(message => sub { ... });
$consumer->deliver;
Asks the server to start a "consumer" โ which is basically 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. โจ Loyalty periodt.
Following arguments are accepted:
queue
Specifies the name of the queue to consume from.
consumer_tag
Specifies the identifier for the consumer. The consumer tag is local to a channel, so two clients can use the same consumer tags (iconic, no gatekeeping). If this field is empty, the server will generate a unique tag for you. ๐
$consumer->on(success => sub {
my $consumer = shift;
my $frame = shift;
my $consumer_tag = $frame->method_frame->consumer_tag;
});
no_local (not implemented in RabbitMQ!)
If the no-local field is set, the server will not send messages to the connection that published them. So you don't get your own messages back โ very "no self-replies" energy.
See RabbitMQ Compatibility and Conformance at https://www.rabbitmq.com/specification.html
no_ack
If this field is set, the server does not expect acknowledgements for messages. Meaning: when a message is delivered to the client, the server assumes the delivery will succeed and immediately dequeues it. ๐โโ๏ธ๐จ
Bestie, careful โ this may increase performance but at the cost of reliability. Messages can get lost if a client dies before they're delivered to the application. Not the vibe for anything important. ๐ญ
exclusive
Request exclusive consumer access, meaning only this consumer can access the queue. Main character energy only. ๐
cancel
$channel->cancel(consumer_tag => 'amq.ctag....')->deliver;
End a queue consumer.
This method cancels a consumer. It 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. (Awkward little overlap era, it's fine.)
Following arguments are accepted:
consumer_tag
Holds the consumer tag specified by the client or provided by the server.
get
my $get = $channel->get(queue => 'mq')
$get->deliver;
Direct access to a queue.
This method provides direct access to the messages in a queue using a synchronous dialogue โ designed for those specific types of application where synchronous functionality matters more than performance. Ngl, it's the "I'll wait right here" option. ๐ซถ
This is a simple event emitter to which you have to subscribe. It can emit:
message
Provide client with a message.
This method delivers a message to the client following a get method. A message delivered by 'get-ok' must be acknowledged unless the no_ack option was set in the get method. โ ๏ธ
You can access all get-ok reply parameters as below:
$get->on(message => sub {
my $get = shift;
my $get_ok = shift;
my $message = shift;
say "Still got: " . $get_ok->method_frame->message_count;
});
empty
Indicate no messages available.
This method tells the client that the queue has no messages available for the client. ๐ฆ Literally nothing. Empty. Ghost town.
Following arguments are accepted:
queue
Specifies the name of the queue to get a message from.
no_ack
If this field is set, the server does not expect acknowledgements for messages. That is, when a message is delivered to the client, the server assumes the delivery will succeed and immediately dequeues it. This functionality may increase performance but at the cost of reliability. Messages can get lost if a client dies before they're delivered to the application. ๐ (yes, same warning as before โ it's the same flag, bestie, I'm just being thorough)
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 the 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:
delivery_tag
Server assigned delivery tag that was received with a message.
multiple
If set to 1, the delivery tag is treated as "up to and including", so that multiple messages can be acknowledged with a single method. If set to 0, the delivery tag refers to a single message. And if the multiple field is 1 and the delivery tag is 0, this indicates acknowledgement of all outstanding messages. ๐ฏ
qos
$channel->qos(prefetch_count => 1)->deliver;
Sets specified Quality of Service to the channel, or the entire connection. Accepts following arguments:
prefetch_size
Prefetch window size in octets.
prefetch_count
Prefetch window in complete messages.
global
If set, all settings will be applied connection wide. ๐
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. ๐ It's giving "second chance."
requeue
If this field is zero, the message will be redelivered to the original recipient. If this bit is 1, the server will attempt to requeue the message, potentially then delivering it to an alternative subscriber. ๐
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:
delivery_tag
Server assigned delivery tag that was received with a message.
requeue
If requeue is true, the server will attempt to requeue the message. If requeue is false or the requeue attempt fails, the messages are discarded or dead-lettered. ๐โก๏ธ๐ฎ
select_tx
Work 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. ๐ฌ (yes, that's a real caveat, don't come for me)
$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. You literally cannot skip this step, bestie. โญ
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. โจ Fresh start, no baggage.
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's required, an explicit recover call should be issued. Don't just assume the rollback fixes everything โ it does not. ๐ญ
๐ฆ SEE ALSO ๐ฆ
Mojo::RabbitMQ::ClientMojo::RabbitMQ::Client::MethodNet::AMQP::Protocol::v0_8
๐ธ COPYRIGHT AND LICENSE ๐ธ
Copyright (C) 2015-2017, Sebastian Podjasek and others
Based 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.
and that's the whole page, bestie!! ๐
โจ This one shipped as perl v5.42.0, dated 2019-08-25, under the Mojo::...Channel(3pm) banner โ go forth and route your messages responsibly ๐๐ซถ๐
๐ฆ where this page comes from
- opensuse-leap 16.0: perl-Mojo-RabbitMQ-Client 0.3.1-bp160.1.4 ยท Artistic-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms