NAME

Net::STOMP::Client::Wrapper - Stomp Client and RabbitMQ Management API wrapper

SYNOPSIS

Producer

use Net::STOMP::Client::Wrapper;
my $wrapper = Net::STOMP::Client::Wrapper->new(queue_name=>"my_queue");   #ISA Net::STOMP::Client::Wrapper
my $stomp   = $wrapper->stomp_connect;                                    #ISA Net::STOMP::Client connected
$wrapper->send(body=>"my_payload");

Consumer

use Net::STOMP::Client::Wrapper;
my $wrapper = Net::STOMP::Client::Wrapper->new(queue_name=>"my_queue");   #ISA Net::STOMP::Client::Wrapper
my $stomp   = $wrapper->stomp_connect_subscribe;                          #ISA Net::STOMP::Client subscribed to queue
$stomp->wait_for_frames(callback => \&queue_callback);

Monitor

use Net::STOMP::Client::Wrapper;
my $wrapper   =  Net::STOMP::Client::Wrapper->new(queue_name=>"my_queue"); #ISA Net::STOMP::Client::Wrapper
my $result    = $wrapper->management_api_get_queue;                       #ISA Net::RabbitMQ::Management::API::Result
my $content   = $result->content;                                         #ISA HASH
my $consumers = $content->{'consumers'} || 0;
my $messages  = $content->{'messages'}  || 0;
printf "Consumers: %s, Messages: %s\n", $consumers, $messages;

Super Class

package My::Wrapper;
use base qw{Net::STOMP::Client::Wrapper};
sub host {"my_host"};
sub queue_name {"my_queue"};

DESCRIPTION

Net::STOMP::Client::Wrapper is a wrapper of Net::STOMP::Client and Net::RabbitMQ::Management::API with sane defaults.

This package is a wrapper for my typical use case which is a single RabbitMQ server with the Stomp and Management API plugins enabled and a single queue_name.

sudo yum install rabbitmq-server
sudo /usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_stomp
sudo /usr/lib/rabbitmq/bin/rabbitmq-plugins enable rabbitmq_management
sudo systemctl enable rabbitmq-server
sudo systemctl start rabbitmq-server

Properties

host

Default: 127.0.0.1

port

Default: 61613

login

Default: guest

passcode

Default: guest

vhost, vhost_url_encoded

Default: /

queue_name, destination

Returns the short queue_name or the formatted destination.

$wrapper->queue_name("my_queue")
my $queue_name  = $wrapper->queue_name;
my $destination = $wrapper->destination; #ISA string formatted as "/queue/{queue_name}"

Default: ''

subscribe_id

Default: {uuid}

subscribe_ack

Default: client

subscribe_prefetch_count

Default: 1

management_api_url

Default: http://{host}:15672/api

Methods

send

Wrapper around `stomp->send` with default destination

$wrapper->send(body=>"my_string"); #destination is defaulted to $wrapper->destination;
$wrapper->send(destination=>"/queue/another_queue", body=>"my_string");

Note: stomp must be connected before calling send.

management_api_get_queue

Returns a Net::RabbitMQ::Management::API::Result object

Object Accessors

stomp_connect_subscribe

Returns a Net::STOMP::Client object connection and subscribed to the configured queue

my $stomp = $wrapper->stomp_connect_subscribe;

Limitations: Only Call once!

stomp_connect

Returns a connected Net::STOMP::Client object.

my $stomp = $wrapper->stomp_connect;

Limitations: Only Call once!

stomp_disconnect

Unsubscribes to any subscriptions and disconnects stomp client.

stomp

Returns the cached Net::STOMP::Client object

management_api

Returns a Net::RabbitMQ::Management::API object

SEE ALSO

Net::STOMP::Client, Net::RabbitMQ::Management::API

AUTHOR

Michael R. Davis

COPYRIGHT AND LICENSE

Copyright (C) 2025 by Michael Davis

LICENSE: MIT