GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Mojo::RabbitMQ::Client::Publisher(3) User Contributed Perl Documentation Mojo::RabbitMQ::Client::Publisher(3)

Mojo::RabbitMQ::Client::Publisher - simple Mojo::RabbitMQ::Client based publisher

  use Mojo::RabbitMQ::Client::Publisher;
  my $publisher = Mojo::RabbitMQ::Client::Publisher->new(
    url => 'amqp://guest:guest@127.0.0.1:5672/?exchange=mojo&routing_key=mojo'
  );

  $publisher->publish_p(
    {encode => { to => 'json'}},
    routing_key => 'mojo_mq'
  )->then(sub {
    say "Message published";
  })->catch(sub {
    die "Publishing failed"
  })->wait;

Mojo::RabbitMQ::Client::Publisher has following attributes.

Sets all connection parameters in one string, according to specification from <https://www.rabbitmq.com/uri-spec.html>.

For detailed description please see Mojo::RabbitMQ::Client#url.

Mojo::RabbitMQ::Client::Publisher implements only single method.

  $publisher->publish_p('simple plain text body');

  $publisher->publish_p({ some => 'json' });

  $publisher->publish_p($body, { header => 'content' }, routing_key => 'mojo', mandatory => 1);

Method signature

  publish_p($body!, \%headers?, *@params)
body
First argument is mandatory body content of published message. Any reference passed here will be encoded as JSON and accordingly "content_type" header will be set to "application/json".
headers
If second argument is a HASHREF it will be merged to message headers.
params
Any other arguments will be considered key/value pairs and passed to the Client's publish method as arguments overriding everything besides body argument.

So this:

  $publisher->publish({ json => 'object' }, { header => 'content' });
    

is similar to this:

  $publisher->publish({ json => 'object' }, header => { header => 'content' });
    

But beware - headers passed as a HASHREF get merged into the header constructed by the Publisher, but params override values; so if you pass "header" as a param like this, it will override the header constructed by the Publisher, and the message will lack the "content_type" header, even though you passed a reference as the body argument! With the first example, the "content_type" header would be included.

Mojo::RabbitMQ::Client

Copyright (C) 2015-2017, Sebastian Podjasek and others

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.

2019-08-20 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.