.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Mojo::RabbitMQ::Client 3pm" .TH Mojo::RabbitMQ::Client 3pm "2022-05-28" "perl v5.34.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mojo::RabbitMQ::Client \- Mojo::IOLoop based RabbitMQ client .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Mojo::RabbitMQ::Client; \& \& # Supply URL according to (https://www.rabbitmq.com/uri\-spec.html) \& my $client = Mojo::RabbitMQ::Client\->new( \& url => \*(Aqamqp://guest:guest@127.0.0.1:5672/\*(Aq); \& \& # Catch all client related errors \& $client\->catch(sub { warn "Some error caught in client"; }); \& \& # When connection is in Open state, open new channel \& $client\->on( \& open => sub { \& my ($client) = @_; \& \& # Create a new channel with auto\-assigned id \& my $channel = Mojo::RabbitMQ::Client::Channel\->new(); \& \& $channel\->catch(sub { warn "Error on channel received"; }); \& \& $channel\->on( \& open => sub { \& my ($channel) = @_; \& $channel\->qos(prefetch_count => 1)\->deliver; \& \& # Publish some example message to test_queue \& my $publish = $channel\->publish( \& exchange => \*(Aqtest\*(Aq, \& routing_key => \*(Aqtest_queue\*(Aq, \& body => \*(AqTest message\*(Aq, \& mandatory => 0, \& immediate => 0, \& header => {} \& ); \& # Deliver this message to server \& $publish\->deliver; \& \& # Start consuming messages from test_queue \& my $consumer = $channel\->consume(queue => \*(Aqtest_queue\*(Aq); \& $consumer\->on(message => sub { say "Got a message" }); \& $consumer\->deliver; \& } \& ); \& $channel\->on(close => sub { $log\->error(\*(AqChannel closed\*(Aq) }); \& \& $client\->open_channel($channel); \& } \& ); \& \& # Start connection \& $client\->connect(); \& \& # Start Mojo::IOLoop if not running already \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .SS "\s-1CONSUMER\s0" .IX Subsection "CONSUMER" .Vb 9 \& use Mojo::RabbitMQ::Client; \& my $consumer = Mojo::RabbitMQ::Client\->consumer( \& url => \*(Aqamqp://guest:guest@127.0.0.1:5672/?exchange=mojo&queue=mojo\*(Aq, \& defaults => { \& qos => {prefetch_count => 1}, \& queue => {durable => 1}, \& consumer => {no_ack => 0}, \& } \& ); \& \& $consumer\->catch(sub { die "Some error caught in Consumer" } ); \& $consumer\->on(\*(Aqsuccess\*(Aq => sub { say "Consumer ready" }); \& $consumer\->on( \& \*(Aqmessage\*(Aq => sub { \& my ($consumer, $message) = @_; \& \& $consumer\->channel\->ack($message)\->deliver; \& } \& ); \& $consumer\->start(); \& \& Mojo::IOLoop\->start unless Mojo::IOLoop\->is_running; .Ve .SS "\s-1PUBLISHER\s0" .IX Subsection "PUBLISHER" .Vb 4 \& use Mojo::RabbitMQ::Client; \& my $publisher = Mojo::RabbitMQ::Client\->publisher( \& url => \*(Aqamqp://guest:guest@127.0.0.1:5672/?exchange=mojo&routing_key=mojo\*(Aq \& ); \& \& $publisher\->publish(\*(Aqplain text\*(Aq); \& \& $publisher\->publish( \& {encode => { to => \*(Aqjson\*(Aq}}, \& routing_key => \*(Aqmojo_mq\*(Aq \& )\->then(sub { \& say "Message published"; \& })\->catch(sub { \& die "Publishing failed" \& })\->wait; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Mojo::RabbitMQ::Client is a rewrite of AnyEvent::RabbitMQ to work on top of Mojo::IOLoop. .SH "EVENTS" .IX Header "EVENTS" Mojo::RabbitMQ::Client inherits all events from Mojo::EventEmitter and can emit the following new ones. .SS "connect" .IX Subsection "connect" .Vb 4 \& $client\->on(connect => sub { \& my ($client, $stream) = @_; \& ... \& }); .Ve .PP Emitted when \s-1TCP/IP\s0 connection with RabbitMQ server is established. .SS "open" .IX Subsection "open" .Vb 4 \& $client\->on(open => sub { \& my ($client) = @_; \& ... \& }); .Ve .PP Emitted \s-1AMQP\s0 protocol Connection.Open\-Ok method is received. .SS "close" .IX Subsection "close" .Vb 4 \& $client\->on(close => sub { \& my ($client) = @_; \& ... \& }); .Ve .PP Emitted on reception of Connection.Close\-Ok method. .SS "disconnect" .IX Subsection "disconnect" .Vb 4 \& $client\->on(close => sub { \& my ($client) = @_; \& ... \& }); .Ve .PP Emitted when \s-1TCP/IP\s0 connection gets disconnected. .SH "ATTRIBUTES" .IX Header "ATTRIBUTES" Mojo::RabbitMQ::Client has following attributes. .SS "tls" .IX Subsection "tls" .Vb 2 \& my $tls = $client\->tls; \& $client = $client\->tls(1) .Ve .PP Force secure connection. Default is disabled (\f(CW0\fR). .SS "user" .IX Subsection "user" .Vb 2 \& my $user = $client\->user; \& $client = $client\->user(\*(Aqguest\*(Aq) .Ve .PP Sets username for authorization, by default it's not defined. .SS "pass" .IX Subsection "pass" .Vb 2 \& my $pass = $client\->pass; \& $client = $client\->pass(\*(Aqsecret\*(Aq) .Ve .PP Sets user password for authorization, by default it's not defined. .SS "host" .IX Subsection "host" .Vb 2 \& my $host = $client\->host; \& $client = $client\->host(\*(Aqlocalhost\*(Aq) .Ve .PP Hostname or \s-1IP\s0 address of RabbitMQ server. Defaults to \f(CW\*(C`localhost\*(C'\fR. .SS "port" .IX Subsection "port" .Vb 2 \& my $port = $client\->port; \& $client = $client\->port(1234) .Ve .PP Port on which RabbitMQ server listens for new connections. Defaults to \f(CW5672\fR, which is standard RabbitMQ server listen port. .SS "vhost" .IX Subsection "vhost" .Vb 2 \& my $vhost = $client\->vhost; \& $client = $client\->vhost(\*(Aq/\*(Aq) .Ve .PP RabbitMQ virtual server to user. Default is \f(CW\*(C`/\*(C'\fR. .SS "params" .IX Subsection "params" .Vb 2 \& my $params = $client\->params; \& $client = $client\->params(Mojo::Parameters\->new(\*(Aqverify=1\*(Aq)) .Ve .PP Sets additional parameters for connection. Default is not defined. .PP For list of supported parameters see \*(L"\s-1SUPPORTED QUERY PARAMETERS\*(R"\s0. .SS "url" .IX Subsection "url" .Vb 2 \& my $url = $client\->url; \& $client = $client\->url(\*(Aqamqp://...\*(Aq); .Ve .PP Sets all connection parameters in one string, according to specification from . .PP .Vb 1 \& amqp_URI = "amqp[s]://" amqp_authority [ "/" vhost ] [ "?" query ] \& \& amqp_authority = [ amqp_userinfo "@" ] host [ ":" port ] \& \& amqp_userinfo = username [ ":" password ] \& \& username = *( unreserved / pct\-encoded / sub\-delims ) \& \& password = *( unreserved / pct\-encoded / sub\-delims ) \& \& vhost = segment .Ve .SS "heartbeat_timeout" .IX Subsection "heartbeat_timeout" .Vb 2 \& my $timeout = $client\->heartbeat_timeout; \& $client = $client\->heartbeat_timeout(180); .Ve .PP Heartbeats are use to monitor peer reachability in \s-1AMQP.\s0 Default value is \f(CW60\fR seconds, if set to \f(CW0\fR no heartbeats will be sent. .SS "connect_timeout" .IX Subsection "connect_timeout" .Vb 2 \& my $timeout = $client\->connect_timeout; \& $client = $client\->connect_timeout(5); .Ve .PP Connection timeout used by Mojo::IOLoop::Client. Defaults to environment variable \f(CW\*(C`MOJO_CONNECT_TIMEOUT\*(C'\fR or \f(CW10\fR seconds if nothing else is set. .SS "max_channels" .IX Subsection "max_channels" .Vb 2 \& my $max_channels = $client\->max_channels; \& $client = $client\->max_channels(10); .Ve .PP Maximum number of channels allowed to be active. Defaults to \f(CW0\fR which means no implicit limit. .PP When you try to call \f(CW\*(C`add_channel\*(C'\fR over limit an \f(CW\*(C`error\*(C'\fR will be emitted on channel saying that: \fIMaximum number of channels reached\fR. .SH "STATIC METHODS" .IX Header "STATIC METHODS" .SS "consumer" .IX Subsection "consumer" .Vb 1 \& my $client = Mojo::RabbitMQ::Client\->consumer(...) .Ve .PP Shortcut for creating Mojo::RabbitMQ::Client::Consumer. .SS "publisher" .IX Subsection "publisher" .Vb 1 \& my $client = Mojo::RabbitMQ::Client\->publisher(...) .Ve .PP Shortcut for creating Mojo::RabbitMQ::Client::Publisher. .SH "METHODS" .IX Header "METHODS" Mojo::RabbitMQ::Client inherits all methods from Mojo::EventEmitter and implements the following new ones. .SS "connect" .IX Subsection "connect" .Vb 1 \& $client\->connect(); .Ve .PP Tries to connect to RabbitMQ server and negotiate \s-1AMQP\s0 protocol. .SS "close" .IX Subsection "close" .Vb 1 \& $client\->close(); .Ve .SS "param" .IX Subsection "param" .Vb 2 \& my $param = $client\->param(\*(Aqname\*(Aq); \& $client = $client\->param(name => \*(Aqvalue\*(Aq); .Ve .SS "add_channel" .IX Subsection "add_channel" .Vb 4 \& my $channel = Mojo::RabbitMQ::Client::Channel\->new(); \& ... \& $channel = $client\->add_channel($channel); \& $channel\->open; .Ve .SS "open_channel" .IX Subsection "open_channel" .Vb 3 \& my $channel = Mojo::RabbitMQ::Client::Channel\->new(); \& ... \& $client\->open_channel($channel); .Ve .SS "delete_channel" .IX Subsection "delete_channel" .Vb 1 \& my $removed = $client\->delete_channel($channel\->id); .Ve .SH "SUPPORTED QUERY PARAMETERS" .IX Header "SUPPORTED QUERY PARAMETERS" There's no formal specification, nevertheless a list of common parameters recognized by officially supported RabbitMQ clients is maintained here: . .PP Some shortcuts are also supported, you'll find them in parenthesis. .PP Aliases are less significant, so when both are specified only primary value will be used. .SS "cacertfile (\fIca\fP)" .IX Subsection "cacertfile (ca)" Path to Certificate Authority file for \s-1TLS.\s0 .SS "certfile (\fIcert\fP)" .IX Subsection "certfile (cert)" Path to the client certificate file for \s-1TLS.\s0 .SS "keyfile (\fIkey\fP)" .IX Subsection "keyfile (key)" Path to the client certificate private key file for \s-1TLS.\s0 .SS "fail_if_no_peer_cert (\fIverify\fP)" .IX Subsection "fail_if_no_peer_cert (verify)" \&\s-1TLS\s0 verification mode, defaults to 0x01 on the client-side if a certificate authority file has been provided, or 0x00 otherwise. .SS "auth_mechanism" .IX Subsection "auth_mechanism" Sets the \s-1AMQP\s0 authentication mechanism. Defaults to \s-1AMQPLAIN. AMQPLAIN\s0 and \&\s-1EXTERNAL\s0 are supported; \s-1EXTERNAL\s0 will only work if Mojo::RabbitMQ::Client does not need to do anything beyond passing along a username and password if specified. .SS "heartbeat" .IX Subsection "heartbeat" Sets requested heartbeat timeout, just like \f(CW\*(C`heartbeat_timeout\*(C'\fR attribute. .SS "connection_timeout (\fItimeout\fP)" .IX Subsection "connection_timeout (timeout)" Sets connection timeout \- see connection_timeout attribute. .SS "channel_max" .IX Subsection "channel_max" Sets maximum number of channels \- see max_channels attribute. .SH "SEE ALSO" .IX Header "SEE ALSO" Mojo::RabbitMQ::Client::Channel, Mojo::RabbitMQ::Client::Consumer, Mojo::RabbitMQ::Client::Publisher .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" Copyright (C) 2015\-2019, Sebastian Podjasek and others .PP Based on AnyEvent::RabbitMQ \- Copyright (C) 2010 Masahito Ikuta, maintained by \f(CW\*(C`bobtfish@bobtfish.net\*(C'\fR .PP This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0. .PP Contains \s-1AMQP\s0 specification (\fIshared/amqp0\-9\-1.stripped.extended.xml\fR) licensed under BSD-style license.