File: cliwaiter_reliable_hb.rb

package info (click to toggle)
ruby-stomp 1.4.10-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 832 kB
  • sloc: ruby: 8,595; sh: 77; makefile: 3
file content (62 lines) | stat: -rw-r--r-- 1,811 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# -*- encoding: utf-8 -*-
#
require 'stomp'
if Kernel.respond_to?(:require_relative)
	require_relative("../examplogger")
  else
	$LOAD_PATH << File.dirname(__FILE__)
	require "../examplogger"
  end
#
# Artemis will summarily close down connections if there is no traffic for some
# time.  This code demonstrates running with a gem connetion parameter using
# heartbeats to totally avoid this Artemis behavior.
#
class CliWaiter

  # Initialize.
  def initialize        # Change the following as needed.
	@gem_retries = true
	@host = ENV['STOMP_HOST'] ? ENV['STOMP_HOST'] : "localhost"
	@port = ENV['STOMP_PORT'] ? ENV['STOMP_PORT'].to_i : 31613 # Artemis here
	@slt = 75
	@ver = ENV['STOMP_PROTOCOL'] ? ENV['STOMP_PROTOCOL'] : "1.2"
	# The Artemis artificial default is to sever after 1 minute of inactivity.
	# The default heart-beat parameters here are chosen just to avoid this
	# Artemis specific behavior.  YMMV.
	@hbdata = ENV['STOMP_HEARTBEATS'] ? ENV['STOMP_HEARTBEATS'] : "59000,59000"
	@conn_hdrs = {"accept-version" => @ver, # version
		"host" => "localhost",              # vhost
		"heart-beat" => @hbdata,            # heartbeats
	}
	mylog = Slogger::new()  # The client provided STOMP callback logger
	@hash = { :hosts => [
				{:login => 'guest', :passcode => 'guest', :host => @host, :port => @port},
		],
		:reliable => @gem_retries, # reliable controls retries by the gem
		:autoflush => true,
		:connect_headers => @conn_hdrs,
		:logger => mylog,	# This enables callback logging!
	}
  end
  # Run example.
  def run()
	puts "CliWaiter Starts"
	puts "Connect Hash is: #{@hash}"
	c = Stomp::Client.new(@hash)
	#
	while true
		# This should run forever.
		puts "CliWaiter Sleeps: #{@slt} seconds"
		sleep @slt
	end
	#
	c.close()
	puts "CliWaiter Ends"
  end
end
#

#
e = CliWaiter.new()
e.run()