The current (0.42) "subscribe" and "unsubscribe" methods assume that we
always subscribe only once per destination.
Since it's possible to specify selectors in a subscription, it makes
sense to subscribe more than once to the same destination, with
different selectors.
The attached patch changes the way the "subscriptions" hash is keyed,
preferring to use subscription ID rather than destination, when the ID
is supplied.
Subject: | net-stomp-subscribe-by-id.patch |
diff --git c/lib/Net/Stomp.pm w/lib/Net/Stomp.pm
index 7d51a39..c0fbabc 100644
--- c/lib/Net/Stomp.pm
+++ w/lib/Net/Stomp.pm
@@ -219,13 +219,20 @@ sub send_transactional {
}
}
+sub _sub_key {
+ my ($conf) = @_;
+
+ if ($conf->{id}) { return "id-".$conf->{id} }
+ return "dest-".$conf->{destination}
+}
+
sub subscribe {
my ( $self, $conf ) = @_;
my $frame = Net::Stomp::Frame->new(
{ command => 'SUBSCRIBE', headers => $conf } );
$self->send_frame($frame);
my $subs = $self->subscriptions;
- $subs->{$conf->{'destination'}} = $conf;
+ $subs->{_sub_key($conf)} = $conf;
}
sub unsubscribe {
@@ -234,7 +241,7 @@ sub unsubscribe {
{ command => 'UNSUBSCRIBE', headers => $conf } );
$self->send_frame($frame);
my $subs = $self->subscriptions;
- delete $subs->{$conf->{'destination'}};
+ delete $subs->{_sub_key($conf)}
}
sub ack {