Net-NATS-Streaming-Client

 view release on metacpan or  search on metacpan

lib/Net/NATS/Streaming/Client.pm  view on Meta::CPAN

    }
    $self->heartbeat_subscription->unsubscribe;
    $self->heartbeat_subscription(undef);
    return $close_response ? $close_response->error : 'failed to close stream';
}

sub close
{
    my $self = shift;
    my $ret = $self->close_stream;
    $self->SUPER::close();
    return $ret;
}

sub run
{
    my ($self, $sub, $timeout) = @_;
    while($self->wait_for_op($timeout//$WAIT_FOR_OP_TIMEOUT))
    {
        last if $sub and $sub->();
    }
}

1;

__END__

=head1 NAME

Net::NATS::Streaming::Client - A Perl client for the NATS Streaming messaging system.

=head1 SYNOPSIS

  #
  # Basic Usage
  #
  This class is a subclass of Net::NATS::Client and delegates all networking
  to the parent.

  $client = Net::NATS::Streaming::Client->new(uri => 'nats://localhost:4222', clientID => 'test_client', clusterID => 'test-cluster');
  $client->connect() or die $!;

  # Simple Async Subscriber
  $subscription = $client->subscribe_channel({ subject => 'foo' }, sub {
      my ($message) = @_;
      printf("Received a message: %s\n", $message->data);
  });
  $self->run;

  # Simple Publisher
  $client->publish_channel({ subject => 'foo', data => 'Hello, World!'});

  # Unsubscribe
  $client->unsubscribe_channel($subscription);

  # Close stream
  $client->close_stream();

=head1 REPOSITORY

L<https://github.com/sergeykolychev/perl-nats-streaming>

=head1 SEE ALSO

L<https://github.com/carwynmoore/perl-nats>
Net::NATS::Client

=head1 AUTHOR

    Sergey Kolychev, <sergeykolychev.github@gmail.com>

=head1 COPYRIGHT & LICENSE

    Copyright (C) 2017 by Sergey Kolychev <sergeykolychev.github@gmail.com>

    This library is licensed under Apache 2.0 license https://www.apache.org/licenses/LICENSE-2.0

=cut



( run in 0.773 second using v1.01-cache-2.11-cpan-39bf76dae61 )