Gianni Ceccarelli

NAME

Net::Stomp::MooseHelpers::CanSubscribe - role for classes that subscribe via Net::Stomp

VERSION

version 2.3

SYNOPSIS

  package MyThing;
  use Moose;
  with 'Net::Stomp::MooseHelpers::CanConnect';
  with 'Net::Stomp::MooseHelpers::CanSubscribe';
  use Try::Tiny;

  sub foo {
    my ($self) = @_;
    $self->connect();
    $self->subscribe();
    do_something( $self->connection->receive_frame() );
  }

DESCRIPTION

This role provides your class with a flexible way to define subscriptions to a STOMP server, and to actually subscribe.

NOTE: as shown in the synopsis, you need 2 separate calls the with, otherwise the roles won't apply. The reason is that this role requires a connection attribute, that is provided by Net::Stomp::MooseHelpers::CanConnect, but the role dependency resolution does not notice that.

ATTRIBUTES

subscribe_headers

Global setting for subscription headers (passed to "subscribe" in Net::Stomp). Can be overridden by the subscribe_headers slot in each element of "servers" and by the headers slot in each element fof "subscriptions". Defaults to the empty hashref.

subscriptions

A SubscriptionConfigList, that is, an arrayref of hashrefs, each of which describes a subscription. Defaults to the empty arrayref. You should set this value to something useful, otherwise your connection will not receive any message.

METHODS

subscribe

Call "subscribe_single" method for each element of "subscriptions", passing the generic "subscribe_headers", the per-server subscribe headers (from current_server, slot subscribe_headers) and the per-subscription subscribe headers (from "subscriptions", slot headers).

Throws a Net::Stomp::MooseHelpers::Exceptions::Stomp if anything goes wrong.

subscribe_single

  $self->subscribe_single($subscription,$headers);

Call the subscribe method on "connection", passing the $headers.

You can override or modify this method in your class if you need to perform more work on each subscription.

AUTHOR

Gianni Ceccarelli <gianni.ceccarelli@net-a-porter.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by Net-a-porter.com.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.