File: logexamp.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 (93 lines) | stat: -rw-r--r-- 3,400 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# -*- encoding: utf-8 -*-

require 'rubygems'
require 'stomp'
require 'logger'  # for the 'local' logger
#
if Kernel.respond_to?(:require_relative)
  require_relative("./stomp_common")  
  require_relative("./examplogger")
else
  $LOAD_PATH << File.dirname(__FILE__)
  require "examplogger"
  require("stomp_common")  
end
include Stomp1xCommon
#
# == A program which demonstrates the callback logging facility.
#
# With appropriate specification of STOMP_PORT, this code should also
# demonstrate failover.
#
class LoggerExample
  # Initialize.
  def initialize
  end
  # Run example.
  def run
    llog =        Logger::new(STDOUT)
    llog.level =  Logger::DEBUG
    llog.debug "LE Starting"

    # //////////////////////////////////////////////////////////////////////////////
    mylog = Slogger::new  # The client provided STOMP callback logger
    # //////////////////////////////////////////////////////////////////////////////
    user =      ENV['STOMP_USER'] ? ENV['STOMP_USER'] : 'guest'
    password =  ENV['STOMP_PASSWORD'] ? ENV['STOMP_PASSWORD'] : 'guest'
    host =      ENV['STOMP_HOST'] ? ENV['STOMP_HOST'] : 'localhost'
    port =      ENV['STOMP_PORT'] ? ENV['STOMP_PORT'].to_i : 61613
    so =        usessl()
    # //////////////////////////////////////////////////////////////////////////////
    # A hash type connect *MUST* be used to enable callback logging.
    # //////////////////////////////////////////////////////////////////////////////
    # Note:  running this example will generate a number of connect failures,
    # because of the fake host in this connect hash.
    # //////////////////////////////////////////////////////////////////////////////
    hash = { :hosts => [
        {:login => user, :passcode => password, :host => 'noonehome', :port => 2525,
          :ssl => so},
        {:login => user, :passcode => password, :host => host, :port => port,
          :ssl => so},
      ],
      :logger => mylog,	# This enables callback logging!
      :max_reconnect_attempts => 5,
    }

    # //////////////////////////////////////////////////////////////////////////////
    # For a Connection:
    llog.debug "LE Connection processing starts"
    conn = Stomp::Connection.new(hash)
    conn.disconnect()

    # //////////////////////////////////////////////////////////////////////////////
    llog.debug "LE Connection processing complete"

    # //////////////////////////////////////////////////////////////////////////////
    # For a Client:
    llog.debug "LE Client processing starts"
    client = Stomp::Client.new(hash)
    client.close()

    # //////////////////////////////////////////////////////////////////////////////
    llog.debug "LE Client processing complete"

    # //////////////////////////////////////////////////////////////////////////////
    # For a Connection with other calls:
    llog.debug "LE Connection Enhanced processing starts"
    conn = Stomp::Connection.new(hash)
    #
    dest = "/queue/loggerq1"
    conn.publish dest, "a logger message"
    conn.subscribe(dest)
    msg = conn.receive()
    conn.disconnect()

    # //////////////////////////////////////////////////////////////////////////////
    llog.debug "LE Connection Enhanced processing complete"

    # //////////////////////////////////////////////////////////////////////////////
    llog.debug "LE Ending"
  end
end
e = LoggerExample.new()
e.run()