AnyEve...Channel(3pm)
π AnyEve...Channel π
okay bestie, we're doing AnyEvent::RabbitMQ::Channel from the Perl docs (3pm, user contributed, the whole vibe) and I am so ready. this is the page, let's go π¦
β¨ NAME β¨
AnyEvent::RabbitMQ::Channel β it's an abstraction of an AMQP channel, periodt.
πΈ SYNOPSIS πΈ
my $ch = $rf->open_channel();
$ch->declare_exchange(exchange => 'test_exchange');
π DESCRIPTION π
so. it's a RabbitMQ channel. that's the whole thing.
a channel is a light-weight virtual connection living inside a TCP connection to a RabbitMQ broker. like, one TCP connection, many lil channels, each doing its own thing. main character energy per channel fr fr π
π«Ά ARGUMENTS FOR open_channel π«Ά
these are the lil guys you can hand over when you open the channel:
on_closeβ a callback that fires when the channel closes. it gets passed the incoming message that caused the close, if there was one. no message, no argument, that's just how it is πon_returnβ a callback that fires when a mandatory or immediate message publish fails. it gets the incoming message, and bestie, that message has accessors:method_frame,header_frame, andbody_frame. very demure, very mindful.
π METHODS π
π« declare_exchange (%args)
declares an exchange on the server β that's the thing you publish messages to. iconic behavior.
Arguments:
on_successβ callback for the good timeline β¨on_failureβ callback for the other timeline πtypeβ default'direct'passiveβ default0durableβ default0auto_deleteβ default0internalβ default0exchangeβ the name of the exchange
π« bind_exchange
binds an exchange to another exchange, with a routing key. matching them up, yk?
Arguments:
sourceβ the name of the source exchange to binddestinationβ the name of the destination exchange to bindrouting_keyβ the routing key to bind with
π« unbind_exchange
(no args listed here, she's just doing her thing π§)
π« delete_exchange
(same, no args listed, bye bestie π)
π« declare_queue
declares a queue on the server β meaning it creates it if it doesn't already exist β so you can publish messages to it.
here's the whole vibe in code:
my $done = AnyEvent->condvar;
$channel->declare_queue(
exchange => $queue_exchange,
queue => $queueName,
durable => 0,
auto_delete => 1,
passive => 0,
arguments => { 'x-expires' => 0, },
on_success => sub { $done->send; },
on_failure => sub {
say "Unable to create queue $queueName";
$done->send;
},
);
$done->recv;
Arguments:
queueβ name of the queue to be declared. π¨ but wait: if the queue name is the empty string, RabbitMQ will create a unique name for the queue for you. this is lowkey the move for temporary/private reply queues. obsessed.on_successβ callback called when the queue was declared successfully. the argument it gets is of typeNet::AMQP::Frame::Method. and if you declared it with an empty name and you're like "okay but what IS the name", you can say:
on_success => sub {
my $method = shift;
my $name = $method->method_frame->queue;
};
on_failureβ callback called when the declaration of the queue has failed πauto_deleteβ0or1, default0passiveβ0or1, default0durableβ0or1, default0exclusiveβ0or1, default0no_ackβ0or1, default1ticketβ default0argumentsβ a hashref of additional parameters which RabbitMQ extensions may use. heads up: this list is not complete, and your RabbitMQ server configuration is what decides which arguments are valid and how they act. so don't come for me if yours is different πx-expiresβ the queue will automatically be removed after being idle for this many milliseconds.- default of
0disables automatic queue removal. (so yes,0= never delete, not "delete instantly", don't get got π)
- default of
π« bind_queue
binds a queue to an exchange, with a routing key.
Arguments:
queueβ the name of the queue to bindexchangeβ the name of the exchange to bindrouting_keyβ the routing key to bind with
π« unbind_queue
(no args listed, still slaying β¨)
π« purge_queue
flushes the contents of a queue. bye bye messages π
π« delete_queue
deletes a queue. β οΈ important: the queue may not have any active consumers. so like, cancel those subscriptions first bestie, don't fight the broker.
π« consume
subscribe to consume messages from a queue. this is the main-character move.
Arguments:
queueβ the name of the queue to be consumed from.on_consumeβ callback called with an argument of the message which has been consumed.- that message is a hash reference, where the value to key
"header"is an object of typeNet::AMQP::Protocol::Basic::ContentHeader,bodyis aNet::AMQP::Frame::Body, and"deliver"aNet::AMQP::Frame::Method. yes, three whole things, she's built different.
- that message is a hash reference, where the value to key
on_cancelβ callback called if consumption is cancelled. this may be at client request, or as a side effect of queue deletion. (and heads up: notification of queue deletion is a RabbitMQ extension, iykyk.)consumer_tagβ identifies this consumer. it'll be auto-generated if you don't provide it, but you must supply a value if you want to be able to cancel the subscription later. no tag, no cancel, fr fr.on_successβ callback called if the subscription was successful (this fires before the first message is consumed).on_failureβ callback called if the subscription fails for any reason.no_ackβ passes through the"no_ack"flag. defaults to1. if it's set to1, the server will not expect messages to be acknowledged.
π« publish
publish a message to an exchange. go little message go π¦
Arguments:
exchangeβ the name of the exchange to send the message to.routing_keyβ the routing key with which to publish the message.headerβ hash of AMQP message header info, including the confusingly similar element"headers", which may contain arbitrary string key/value pairs. yes it's confusing. yes it's real. we deal πbodyβ the text body of the message to send.mandatoryβ boolean. if true, then if the message doesn't land in a queue (like, say, the exchange has no bindings), it will be "returned." (see"on_return"below β¬οΈ)immediateβ boolean. if true, then if the message cannot be delivered directly to a consumer, it will be "returned." (see"on_return"below β¬οΈ)on_ackβ callback called with the frame that acknowledges receipt (if the channel is in confirm mode), typicallyNet::AMQP::Protocol::Basic::Ack.on_nackβ callback called with the frame that declines receipt (if the channel is in confirm mode), typicallyNet::AMQP::Protocol::Basic::NackorNet::AMQP::Protocol::Channel::Close.on_returnβ okay so in AMQP, a "returned" message is one that cannot be delivered in compliance with the"immediate"or"mandatory"flags.- if in confirm mode, this callback will be called with the frame that reports message return, typically
Net::AMQP::Protocol::Basic::Return. if confirm mode is off, or this callback isn't provided, then the channel or connection objects'on_returncallbacks (if any) get called instead. - > NOTE: if confirm mode is on, the
on_ackoron_nackcallback will be called whether or noton_returnis called first. so don't assume an order, bestie, just be ready for both π
- if in confirm mode, this callback will be called with the frame that reports message return, typically
π« cancel
cancel a queue subscription.
π’ important nuance: the cancellation will not take place at once, and further messages may be consumed before the subscription is actually cancelled. no further messages will be consumed after the on_success callback has been called, though. so there's a lil messy middle window. that's just how she goes.
Arguments:
consumer_tagβ identifies this consumer. it needs to be the value you supplied when the queue was initially consumed from.on_successβ callback called if the subscription was successfully cancelled.on_failureβ callback called if the subscription could not be cancelled for any reason.
π« get
try to get a single message from a queue. just one. a lil snack. π
Arguments:
queueβ Mandatory. name of the queue to try to receive a message from.on_successβ will be called either with a message, or, if the queue is empty, a notification that there was nothing to collect from the queue. (so yeah, success can mean "nothing there", be chill about it β¨)on_failureβ this callback will be called if an error is signalled on this channel.no_ackβ0or1, default1
π« ack
(no args listed on the page, she's a vibe π§)
π« qos
(no args listed either, still iconic)
π« confirm
puts the channel into confirm mode. in confirm mode, publishes are confirmed by the server, so the on_ack callback of publish actually works. that's the whole point, bestie. π
π« recover
(no args listed)
π« select_tx
(no args listed)
π« commit_tx
(no args listed)
π« rollback_tx
(no args listed)
π AUTHOR, COPYRIGHT AND LICENSE π
for author(s), copyright and license, go check out AnyEvent::RabbitMQ β that's where all of it lives, this page is just the channel chapter π
and that's a wrap on the AnyEve...Channel(3pm) page from the User Contributed Perl Documentation, generated with perl v5.32.1 and dated 2021-09-12. tysm for reading, go declare some queues responsibly, mwah π«Άπ
β¨
π¦ where this page comes from
- debian bookworm: libanyevent-rabbitmq-perl 1.22~dfsg-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libanyevent-rabbitmq-perl 1.22~dfsg-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu jammy: libanyevent-rabbitmq-perl 1.22~dfsg-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libanyevent-rabbitmq-perl 1.22~dfsg-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libanyevent-rabbitmq-perl 1.22~dfsg-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libanyevent-rabbitmq-perl 1.22~dfsg-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms