stomp 1.3.5 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,75 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'rubygems'
4
+ require 'stomp'
5
+
6
+ if Kernel.respond_to?(:require_relative)
7
+ require_relative("./stomp11_common")
8
+ require_relative("./lflogger")
9
+ else
10
+ $LOAD_PATH << File.dirname(__FILE__)
11
+ require "stomp11_common"
12
+ require "./lflogger"
13
+ end
14
+ include Stomp11Common
15
+ #
16
+ # Used primarily for testing performance when sending "large" messages.
17
+ # "large" => YMMV
18
+ #
19
+ class FileSenderConn
20
+ # Initialize.
21
+ def initialize
22
+ end
23
+ # Run example.
24
+ def run
25
+ p [ "pubc001", Thread.current ]
26
+ publogger = Slogger::new
27
+ start_time = Time.now.to_f
28
+ fname = ARGV[0]
29
+ puts "PUBFC: File Name: #{fname}"
30
+ file = open(fname, "r")
31
+ rs = Time.now.to_f
32
+ buff = file.read
33
+ re = Time.now.to_f
34
+ ppt = sprintf("%20.6f", re - rs)
35
+ puts "PUBFC: File size: #{buff.respond_to?(:bytesize) ? buff.bytesize : buff.length}"
36
+ puts "PUBFC: File read: #{ppt} seconds"
37
+ file.close
38
+ #
39
+ connection_hdrs = {"accept-version" => "1.1",
40
+ "host" => virt_host(),
41
+ }
42
+ connection_hash = { :hosts => [
43
+ {:login => login(), :passcode => passcode(),
44
+ :host => host(), :port => port()},
45
+ ],
46
+ :connect_headers => connection_hdrs,
47
+ :logger => publogger,
48
+ :reliable => false, ### *NOTE*
49
+ }
50
+ #
51
+ # p [ "ch", connection_hash ]
52
+ connection = Stomp::Connection.new(connection_hash)
53
+ qname = ENV['STOMP_DEST'] ? ENV['STOMP_DEST'] : "/queue/a.big.file"
54
+ puts "PUBFC: Qname is: #{qname}"
55
+ ph = {:presistent => true}
56
+ ph['suppress_content_length'] = 'yes' if suppresscl()
57
+ puts "PUBF: Headers are: #{ph.inspect}"
58
+ # Try to gracefully handle files that exceed broker size limits.
59
+ begin
60
+ connection.publish(qname, buff, ph)
61
+ rescue
62
+ puts "PUBFC: exception on publish: #{$!}"
63
+ end
64
+ e = connection.poll() # Check for unsolicited messages from broker
65
+ puts "PUBFC: unexpected broker message: #{e}" if e
66
+ connection.disconnect
67
+ end_time = Time.now.to_f
68
+ ppt = sprintf("%20.6f", end_time - start_time)
69
+ puts "PUBFC: File published: #{ppt} seconds"
70
+ end
71
+ end
72
+ #
73
+ e = FileSenderConn.new
74
+ e.run
75
+
@@ -21,7 +21,7 @@ module Stomp11Common
21
21
  end
22
22
  # Server port
23
23
  def port()
24
- (ENV['STOMP_PORT'] || 62613).to_i # !! The author runs Apollo listening here
24
+ (ENV['STOMP_PORT'] || 61613).to_i # !! The author runs AMQ listening here
25
25
  end
26
26
  # Required vhost name
27
27
  def virt_host()
@@ -44,5 +44,11 @@ module Stomp11Common
44
44
  def nmsgs()
45
45
  (ENV['STOMP_NMSGS'] || 1).to_i # Number of messages
46
46
  end
47
+
48
+ # Include "suppress-content-length' header
49
+ def suppresscl()
50
+ ENV['STOMP_SUPPRESS_CL']
51
+ end
52
+
47
53
  end
48
54
 
data/lib/client/utils.rb CHANGED
@@ -20,8 +20,11 @@ module Stomp
20
20
  end
21
21
 
22
22
  def parse_stomp_url(login)
23
+ original_verbose, $VERBOSE = $VERBOSE, nil # shut off warnings
23
24
  regexp = /^stomp:\/\/#{URL_REPAT}/
24
- return false unless url = regexp.match(login)
25
+ url = regexp.match(login)
26
+ $VERBOSE = original_verbose
27
+ return false unless url
25
28
 
26
29
  @parameters = { :reliable => false,
27
30
  :hosts => [ { :login => url[3] || "",
@@ -34,7 +37,10 @@ module Stomp
34
37
  # e.g. failover://(stomp://login1:passcode1@localhost:61616,stomp://login2:passcode2@remotehost:61617)?option1=param
35
38
  def parse_failover_url(login)
36
39
  rval = nil
37
- if md = FAILOVER_REGEX.match(login)
40
+ original_verbose, $VERBOSE = $VERBOSE, nil # shut off warnings
41
+ md = FAILOVER_REGEX.match(login)
42
+ $VERBOSE = original_verbose
43
+ if md
38
44
  finhosts = parse_hosts(login)
39
45
 
40
46
  options = {}
@@ -75,6 +81,7 @@ module Stomp
75
81
  # Parse a stomp URL.
76
82
  def parse_hosts(url)
77
83
  hosts = []
84
+ original_verbose, $VERBOSE = $VERBOSE, nil # shut off warnings
78
85
  host_match = /stomp(\+ssl)?:\/\/#{URL_REPAT}/
79
86
  url.scan(host_match).each do |match|
80
87
  host = {}
@@ -85,6 +92,7 @@ module Stomp
85
92
  host[:port] = match[6].to_i
86
93
  hosts << host
87
94
  end
95
+ $VERBOSE = original_verbose
88
96
  hosts
89
97
  end
90
98
 
@@ -253,6 +253,7 @@ module Stomp
253
253
  end
254
254
  @socket = nil
255
255
  used_socket = socket()
256
+ return used_socket
256
257
  end
257
258
 
258
259
  end # class Connection