Perl Diver 2.31
Main Environment Variables Perl Default Values Perl Config - Summary Perl Config - Full Installed Modules List Directory uptime Docs

Module Documentation
Details and documentation about a specific module, including version and documentation (if available). Note that while links to perldoc.com and search.cpan.org are provided, the module may be part of a larger distribution. If you reach a File Not Found page on either site, please try the parent module.

Net::STOMP::Client::HeartBeat

Name Net::STOMP::Client::HeartBeat
Version 2.5
Located at /usr/share/perl5/vendor_perl
File /usr/share/perl5/vendor_perl/Net/STOMP/Client/HeartBeat.pm
Is Core No
Search CPAN for this module Net::STOMP::Client::HeartBeat
Documentation Net::STOMP::Client::HeartBeat
Module Details Net::STOMP::Client::HeartBeat

NAME

Net::STOMP::Client::HeartBeat - Heart-beat support for Net::STOMP::Client


SYNOPSIS

  use Net::STOMP::Client;
  $stomp = Net::STOMP::Client->new(host => "127.0.0.1", port => 61613);
  ...
  # can set the desired configuration only _before_ connect()
  # the client can send heart-beats every 5 seconds
  $stomp->client_heart_beat(5);
  # the server should send heart-beats every 10 seconds
  $stomp->server_heart_beat(10);
  ...
  $stomp->connect();
  ...
  # can get the negotiated configuration only _after_ connect()
  printf("negotiated heart-beats: client=%.3f server=%.3f\n",
      $stomp->client_heart_beat(), $stomp->server_heart_beat());


DESCRIPTION

This module handles STOMP heart-beat negotiation. It is used internally by the Net::STOMP::Client manpage and should not be directly used elsewhere.


METHODS

This module provides the following methods to the Net::STOMP::Client manpage:

client_heart_beat([VALUE])
get/set the client heart-beat

server_heart_beat([VALUE])
get/set the server heart-beat

last_received()
get the time at which data was last received, i.e. read from the network socket

last_sent()
get the time at which data was last sent, i.e. written to the network socket

beat([OPTIONS])
send a NOOP frame (using the noop() method) unless the last sent time is recent enough with regard to the client heart-beat settings

For consistency with other Perl modules (for instance the Time::HiRes manpage), time is always expressed as a fractional number of seconds.


HEART-BEATING

Starting with STOMP 1.1, each end of a STOMP connection can check if the other end is alive via heart-beating.

In order to use heart-beating (which is disabled by default), the client must specify what it wants before sending the CONNECT frame. This can be done using the client_heart_beat and server_heart_beat options of the new() method or, this is equivalent, the client_heart_beat() and server_heart_beat() methods on the the Net::STOMP::Client manpage object.

After having received the CONNECTED frame, the client_heart_beat() and server_heart_beat() methods can be used to get the negotiated values.

To prove that it is alive, the client just needs to call the beat() method when convenient.

To check if the server is alive, the client just needs to compare the current time and what is returned by the last_received() and server_heart_beat() methods. For instance:

  $delta = $stomp->server_heart_beat();
  if ($delta) {
      $inactivity = Time::HiRes::time() - $stomp->last_received();
      printf("server looks dead!\n") if $inactivity > $delta;
  }


SEE ALSO

the Net::STOMP::Client manpage, the Time::HiRes manpage.


AUTHOR

Lionel Cons http://cern.ch/lionel.cons

Copyright (C) CERN 2010-2021

Perl Diver brought to you by ScriptSolutions.com © 1997- 2025