stomp 1.3.5 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+ if Kernel.respond_to?(:require_relative)
3
+ require_relative("payload_generator")
4
+ else
5
+ $LOAD_PATH << File.dirname(__FILE__)
6
+ require "payload_generator"
7
+ end
8
+ #
9
+ cmin, cmax = 1292, 67782
10
+ ffmts = "%16.6f"
11
+ #
12
+ PayloadGenerator::initialize(min= cmin, max= cmax)
13
+
14
+ to, nmts, nts, umps = 0.0, Time.now.to_f, 100, 5.6
15
+ # p [ "nmts", nmts ]
16
+ tslt = 1.0 / umps
17
+ # p [ "tslt", tslt ]
18
+ nts.times do |i|
19
+ ns = PayloadGenerator::payload()
20
+ to += ns.bytesize
21
+ # puts "t: #{i+1}, len: #{ns.bytesize}, tslt: #{tslt}"
22
+ sleep(tslt)
23
+ # puts "Done sleep!"
24
+ end
25
+ #
26
+ te = Time.now.to_f
27
+ # p [ "te", te ]
28
+ et = te - nmts
29
+ avgsz = to / nts
30
+ mps = nts.to_f / et
31
+ #
32
+ fet = sprintf(ffmts, et)
33
+ favgsz = sprintf(ffmts, avgsz)
34
+ fmps = sprintf(ffmts, mps)
35
+ #
36
+ puts "=" * 48
37
+ puts "\tNumber of payloads generated: #{nts}"
38
+ puts "\tMin Length: #{cmin}, Max Length: #{cmax}"
39
+ puts "\tAVG_SIZE: #{favgsz}, ELAPS_SEC: #{fet}(seconds)"
40
+ puts "\tNMSGS_PER_SEC: #{fmps}"
41
+ #
@@ -0,0 +1,99 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ #
4
+ # Common Stomp 1.1 code.
5
+ #
6
+ require "rubygems" if RUBY_VERSION < "1.9"
7
+ require "stomp"
8
+ #
9
+ module Stomp11Common
10
+ # Port Constants locally
11
+ STOMP_AMQ_PORT = ENV['STOMP_AMQ_PORT'] ? ENV['STOMP_AMQ_PORT'].to_i : 61613
12
+ STOMP_APOLLO_PORT = ENV['STOMP_APOLLO_PORT'] ? ENV['STOMP_APOLLO_PORT'].to_i : 62613
13
+ STOMP_ARTEMIS_PORT = ENV['STOMP_ARTEMIS_PORT'] ? ENV['STOMP_ARTEMIS_PORT'].to_i : 31613
14
+ STOMP_SSNG_PORT = ENV['STOMP_SSNG_PORT'] ? ENV['STOMP_SSNG_PORT'].to_i : 51613
15
+ STOMP_RMQ_PORT = ENV['STOMP_RMQ_PORT'] ? ENV['STOMP_RMQ_PORT'].to_i : 41613
16
+
17
+ # Vhost Constants
18
+ STOMP_RMQ_VHOST = ENV['STOMP_RMQ_VHOST'] || '/'
19
+ STOMP_VHOST = ENV['STOMP_VHOST'] || 'localhost'
20
+
21
+ # Client Protocol List
22
+ STOMP_PROTOCOL = ENV['STOMP_PROTOCOL'] || "1.2"
23
+
24
+ # User id
25
+ def login()
26
+ ENV['STOMP_USER'] || 'guest'
27
+ end
28
+ # Password
29
+ def passcode()
30
+ ENV['STOMP_PASSCODE'] || 'guest'
31
+ end
32
+ # Server host
33
+ def host()
34
+ ENV['STOMP_HOST'] || "localhost" # The connect host name
35
+ end
36
+ # Server port
37
+ def port()
38
+ if ENV['STOMP_AMQ']
39
+ STOMP_AMQ_PORT
40
+ elsif ENV['STOMP_APOLLO']
41
+ STOMP_APOLLO_PORT
42
+ elsif ENV['STOMP_RMQ']
43
+ STOMP_RMQ_PORT
44
+ elsif ENV['STOMP_SSNG']
45
+ STOMP_SSNG_PORT
46
+ elsif ENV['STOMP_PORT']
47
+ ENV['STOMP_PORT'].to_i
48
+ else
49
+ 61613 # The default ActiveMQ stomp listener port
50
+ end
51
+ end
52
+ # Required vhost name
53
+ def virt_host()
54
+ if ENV['STOMP_RMQ']
55
+ STOMP_RMQ_VHOST
56
+ else
57
+ STOMP_VHOST
58
+ end
59
+ end
60
+ # Create a 1.1 commection
61
+ def get_connection()
62
+ conn_hdrs = {"accept-version" => STOMP_PROTOCOL,
63
+ "host" => virt_host(), # the vhost
64
+ }
65
+ conn_hash = { :hosts => [
66
+ {:login => login(), :passcode => passcode(), :host => host(), :port => port()},
67
+ ],
68
+ :connect_headers => conn_hdrs,
69
+ }
70
+ conn = Stomp::Connection.new(conn_hash)
71
+ end
72
+
73
+ # Number of messages
74
+ def nmsgs()
75
+ (ENV['STOMP_NMSGS'] || 1).to_i # Number of messages
76
+ end
77
+
78
+ # Queue / Topic Name
79
+ def make_destination(right_part = nil, topic = false)
80
+ if ENV['STOMP_DOTQUEUE']
81
+ right_part.gsub!('/', '.')
82
+ end
83
+ if topic
84
+ "/topic/#{right_part}"
85
+ else
86
+ "/queue/#{right_part}"
87
+ end
88
+ end
89
+
90
+ # True if client should supply a receipt block on 'publish'
91
+ def cli_block()
92
+ ENV['STOMP_CLI_BLOCK']
93
+ end
94
+
95
+ # True if connection should ask for a receipt
96
+ def conn_receipt()
97
+ ENV['STOMP_RECEIPT']
98
+ end
99
+ end # module
@@ -0,0 +1,63 @@
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 receiving "large" messages.
17
+ # "large" => YMMV
18
+ #
19
+ class FileReader
20
+ # Initialize.
21
+ def initialize(pto)
22
+ @parse_timeout = pto
23
+ end
24
+ # Run example.
25
+ def run
26
+ conlogger = Slogger::new
27
+ start_time = Time.now.to_f
28
+ #
29
+ connection_hdrs = {"accept-version" => "1.1",
30
+ "host" => virt_host(),
31
+ }
32
+ connection_hash = { :hosts => [
33
+ {:login => login(), :passcode => passcode(),
34
+ :host => host(), :port => port()},
35
+ ],
36
+ :connect_headers => connection_hdrs,
37
+ :logger => conlogger,
38
+ :reliable => false,
39
+ :parse_timeout => @parse_timeout,
40
+ }
41
+ #
42
+ # p [ "ch", connection_hash ]
43
+ connection = Stomp::Connection.new(connection_hash)
44
+ qname = ENV['STOMP_DEST'] ? ENV['STOMP_DEST'] : "/queue/a.big.file"
45
+ puts "CONF: Qname is: #{qname}"
46
+ ## connection.subscribe(qname, {:destination => qname}, "bigFileSubscriptionID")
47
+ connection.subscribe(qname, {:destination => qname}, connection.uuid())
48
+ ## connection.subscribe(qname, {:destination => qname}, "0")
49
+ msg = connection.receive()
50
+ puts "CONF: Message Command: #{msg.command}"
51
+ puts "CONF: Message Headers: #{msg.headers}"
52
+ body_length_bytes = msg.body.respond_to?(:bytesize) ? msg.body.bytesize : msg.body.length
53
+ puts "CONF: Received: #{body_length_bytes} bytes"
54
+ connection.disconnect
55
+ end_time = Time.now.to_f
56
+ ppt = sprintf("%20.6f", end_time - start_time)
57
+ puts "CONF: File consumed: #{ppt} seconds"
58
+ end
59
+ end
60
+ #
61
+ e = FileReader.new(60)
62
+ e.run
63
+
@@ -0,0 +1,6 @@
1
+ #!/bin/bash
2
+ #
3
+ # git log --reverse --all --date=short --pretty --format='%aI;%cI;%cn;%ce' | \
4
+ git log --reverse --all --date=short --pretty --format='%ad;%cd;%cn;%ce' | \
5
+ ruby examples/contributors.rb
6
+
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ class UserData
4
+
5
+ public
6
+ attr_accessor :count
7
+ attr_reader :ad, :cd
8
+ #
9
+ def initialize(ad = nil, cd = nil)
10
+ @count, @ad, @cd = 1, ad, cd
11
+ end
12
+ #
13
+ def to_s
14
+ "UserData: AuthorDate=>#{@ad}, CommitDate=>#{@cd}, CommitCount =>#{@count}"
15
+ end
16
+ end
17
+ # tABLE Data
18
+ ttab_s = "<table border=\"1\" style=\"width:100%;border: 1px solid black;\">\n"
19
+ ttab_e = "</table>\n"
20
+ # Row Data
21
+ trow_s = "<tr>\n"
22
+ trow_e = "</tr>\n"
23
+ # Header Data
24
+ th_s = "<th style=\"border: 1px solid black;padding-left: 10px;\" >\n"
25
+ th_c1 = "First Author Date"
26
+ th_c1b = "First Commit Date"
27
+ th_c2 = "(Commit Count)"
28
+ th_c3 = "Name / E-mail"
29
+ th_e = "</th>\n"
30
+ # User Data (partial)
31
+ td_s = "<td style=\"border: 1px solid black;padding-left: 10px;\" >\n"
32
+ td_e = "</td>\n"
33
+ #
34
+ puts ttab_s # table start
35
+ #
36
+ userList = {}
37
+ while s = gets do
38
+ s.chomp!
39
+ ad, cd, n, e = s.split(";")
40
+ hk = "#{n}|#{e}"
41
+ if userList.has_key?(hk)
42
+ userList[hk].count += 1
43
+ else
44
+ userList[hk] = UserData.new(ad, cd)
45
+ =begin
46
+ if ad != cd
47
+ puts "NE: #{ad}, #{cd}, #{n}, #{e}"
48
+ end
49
+ =end
50
+ end
51
+
52
+ end
53
+ #
54
+ puts trow_s
55
+ #
56
+ puts th_s
57
+ puts th_c1
58
+ puts th_e
59
+ #
60
+ =begin
61
+ puts th_s
62
+ puts th_c1b
63
+ puts th_e
64
+ =end
65
+ #
66
+ puts th_s
67
+ puts th_c2
68
+ puts th_e
69
+ #
70
+ puts th_s
71
+ puts th_c3
72
+ puts th_e
73
+ #
74
+ puts trow_e
75
+ #
76
+ userList.each do |k, v|
77
+ n, e = k.split("|")
78
+ oc = "(" + sprintf("%04d", v.count) + ")"
79
+ # puts "# #{v.time} (#{oc}) #{n} #{e}"
80
+ puts trow_s
81
+ #
82
+ puts td_s
83
+ puts "#{v.ad}"
84
+ puts td_e
85
+ =begin
86
+ #
87
+ puts td_s
88
+ puts "#{v.cd}"
89
+ puts td_e
90
+ =end
91
+ #
92
+ puts td_s
93
+ puts oc
94
+ puts td_e
95
+ #
96
+ puts td_s
97
+ puts "<span style=\"font-weight: bold;\" >\n"
98
+ puts "#{n}\n"
99
+ puts "</span>\n"
100
+ puts " / #{e}"
101
+ puts td_e
102
+ #
103
+ puts trow_e
104
+ end
105
+ #
106
+ puts ttab_e # table end
@@ -0,0 +1,316 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require 'logger' # use the standard Ruby logger .....
4
+
5
+ # == Example STOMP call back logger class.
6
+ #
7
+ # Optional callback methods:
8
+ #
9
+ # * on_connecting: connection starting
10
+ # * on_connected: successful connect
11
+ # * on_connectfail: unsuccessful connect (will usually be retried)
12
+ # * on_disconnect: successful disconnect
13
+ #
14
+ # * on_miscerr: on miscellaneous xmit/recv errors
15
+ #
16
+ # * on_publish: publish called
17
+ # * on_subscribe: subscribe called
18
+ # * on_unsubscribe: unsubscribe called
19
+ #
20
+ # * on_begin: begin called
21
+ # * on_ack: ack called
22
+ # * on_nack: nack called
23
+ # * on_commit: commit called
24
+ # * on_abort: abort called
25
+ #
26
+ # * on_receive: receive called and successful
27
+ #
28
+ # * on_ssl_connecting: SSL connection starting
29
+ # * on_ssl_connected: successful SSL connect
30
+ # * on_ssl_connectfail: unsuccessful SSL connect (will usually be retried)
31
+ #
32
+ # * on_hbread_fail: unsuccessful Heartbeat read
33
+ # * on_hbwrite_fail: unsuccessful Heartbeat write
34
+ # * on_hbfire: on any send or receive heartbeat
35
+ #
36
+ # All methods are optional, at the user's requirements.
37
+ #
38
+ # If a method is not provided, it is not called (of course.)
39
+ #
40
+ # IMPORTANT NOTE: in general, call back logging methods *SHOULD* not raise exceptions,
41
+ # otherwise the underlying STOMP connection may fail in mysterious ways.
42
+ # There are, however, exceptions to this 'rule'.
43
+ #
44
+ # Useful exceptions to this rule are:
45
+ #
46
+ # * on_connectfail
47
+ # * on_ssl_connectfail
48
+ #
49
+ # These two methods can raise a Stomp::Errors::LoggerConnectionError. If this
50
+ # exception is raised, it is passed up the chain to the caller.
51
+ #
52
+ # Callback parameters: are a copy of the @parameters instance variable for
53
+ # the Stomp::Connection.
54
+ #
55
+ # A logger class may optionally inherit from the provided NullLogger
56
+ #
57
+ # # class Slogger < Stomp::NullLogger
58
+ #
59
+ class Slogger
60
+
61
+ MAX_BODY_LEN = 1024 # Arbitrary
62
+
63
+ # Initialize a new callback logger instance.
64
+ def initialize(init_parms = nil)
65
+ _init
66
+ @log.info("Logger initialization complete.")
67
+ end
68
+
69
+ def _init
70
+ @log = Logger::new(STDOUT) # User preference
71
+ @log.level = Logger::DEBUG # User preference
72
+ end
73
+
74
+ def marshal_dump
75
+ []
76
+ end
77
+
78
+ def marshal_load(array)
79
+ _init
80
+ end
81
+
82
+ # Log connecting events
83
+ def on_connecting(parms)
84
+ begin
85
+ @log.debug "Connecting: #{info(parms)}"
86
+ rescue
87
+ @log.debug "Connecting oops #{$!}"
88
+ end
89
+ end
90
+
91
+ # Log connected events
92
+ def on_connected(parms)
93
+ begin
94
+ @log.debug "Connected Info: #{info(parms)}"
95
+ @log.debug "Connected Parms: #{parms}"
96
+ rescue
97
+ @log.debug "Connected oops #{$!}"
98
+ end
99
+ end
100
+
101
+ # Log connectfail events
102
+ def on_connectfail(parms)
103
+ begin
104
+ @log.debug "Connect Fail #{info(parms)}"
105
+ rescue
106
+ @log.debug "Connect Fail oops #{$!}"
107
+ end
108
+ =begin
109
+ # An example LoggerConnectionError raise
110
+ @log.debug "Connect Fail, will raise"
111
+ raise Stomp::Error::LoggerConnectionError.new("quit from connect fail")
112
+ =end
113
+ end
114
+
115
+ # Log disconnect events
116
+ def on_disconnect(parms)
117
+ begin
118
+ @log.debug "Disconnected #{info(parms)}"
119
+ rescue
120
+ @log.debug "Disconnected oops #{$!}"
121
+ end
122
+ end
123
+
124
+ # Log miscellaneous errors
125
+ def on_miscerr(parms, errstr)
126
+ begin
127
+ @log.debug "Miscellaneous Error Info: #{info(parms)}"
128
+ @log.debug "Miscellaneous Error String: #{errstr}"
129
+ @log.debug "Miscellaneous Error Parms: #{parms}"
130
+ rescue
131
+ @log.debug "Miscellaneous Error oops #{$!}"
132
+ # Most clients will want to know about this. YMMV
133
+ raise
134
+ end
135
+ end
136
+
137
+ # Log Subscribe
138
+ def on_subscribe(parms, headers)
139
+ begin
140
+ @log.debug "Subscribe Parms #{info(parms)}"
141
+ @log.debug "Subscribe Headers #{headers}"
142
+ rescue
143
+ @log.debug "Subscribe oops #{$!}"
144
+ end
145
+ end
146
+
147
+ # Log UnSubscribe
148
+ def on_unsubscribe(parms, headers)
149
+ begin
150
+ @log.debug "UnSubscribe Parms #{info(parms)}"
151
+ @log.debug "UnSubscribe Headers #{headers}"
152
+ rescue
153
+ @log.debug "UnSubscribe oops #{$!}"
154
+ end
155
+ end
156
+
157
+ # Log Publish
158
+ def on_publish(parms, body, headers)
159
+ begin
160
+ @log.debug "Publish Parms #{info(parms)}"
161
+ body_length_bytes = body.respond_to?(:bytesize) ? body.bytesize : body.length
162
+ @log.debug "Publish Message Body #{body}" if body_length_bytes <= MAX_BODY_LEN
163
+ @log.debug "Publish Headers #{headers}"
164
+ rescue
165
+ @log.debug "Publish oops #{$!}"
166
+ end
167
+ end
168
+
169
+ # Log Receive
170
+ def on_receive(parms, result)
171
+ begin
172
+ @log.debug "Receive Parms #{info(parms)}"
173
+ @log.debug result.is_a? Stomp::Message
174
+ ## @log.debug "Receive Result #{result}"
175
+ rescue
176
+ @log.debug "Receive oops #{$!}"
177
+ end
178
+ end
179
+
180
+ # Log Begin
181
+ def on_begin(parms, headers)
182
+ begin
183
+ @log.debug "Begin Parms #{info(parms)}"
184
+ @log.debug "Begin Result #{headers}"
185
+ rescue
186
+ @log.debug "Begin oops #{$!}"
187
+ end
188
+ end
189
+
190
+ # Log Ack
191
+ def on_ack(parms, headers)
192
+ begin
193
+ @log.debug "Ack Parms #{info(parms)}"
194
+ @log.debug "Ack Result #{headers}"
195
+ rescue
196
+ @log.debug "Ack oops #{$!}"
197
+ end
198
+ end
199
+
200
+ # Log NAck
201
+ def on_nack(parms, headers)
202
+ begin
203
+ @log.debug "NAck Parms #{info(parms)}"
204
+ @log.debug "NAck Result #{headers}"
205
+ rescue
206
+ @log.debug "NAck oops #{$!}"
207
+ end
208
+ end
209
+
210
+ # Log Commit
211
+ def on_commit(parms, headers)
212
+ begin
213
+ @log.debug "Commit Parms #{info(parms)}"
214
+ @log.debug "Commit Result #{headers}"
215
+ rescue
216
+ @log.debug "Commit oops #{$!}"
217
+ end
218
+ end
219
+
220
+ # Log Abort
221
+ def on_abort(parms, headers)
222
+ begin
223
+ @log.debug "Abort Parms #{info(parms)}"
224
+ @log.debug "Abort Result #{headers}"
225
+ rescue
226
+ @log.debug "Abort oops #{$!}"
227
+ end
228
+ end
229
+
230
+ # Stomp 1.1+ - heart beat read (receive) failed.
231
+ def on_hbread_fail(parms, ticker_data = {})
232
+ begin
233
+ @log.debug "Hbreadf Parms #{info(parms)}"
234
+ @log.debug "Hbreadf Result #{ticker_data.inspect}"
235
+ rescue
236
+ @log.debug "Hbreadf oops #{$!}"
237
+ end
238
+ end
239
+
240
+ # Stomp 1.1+ - heart beat send (transmit) failed.
241
+ def on_hbwrite_fail(parms, ticker_data = {})
242
+ begin
243
+ @log.debug "Hbwritef Parms #{info(parms)}"
244
+ @log.debug "Hbwritef Result #{ticker_data.inspect}"
245
+ rescue
246
+ @log.debug "Hbwritef oops #{$!}"
247
+ end
248
+ end
249
+
250
+ # Log SSL connection start.
251
+ def on_ssl_connecting(parms)
252
+ begin
253
+ @log.debug "SSL Connecting Parms #{info(parms)}"
254
+ rescue
255
+ @log.debug "SSL Connecting oops #{$!}"
256
+ end
257
+ end
258
+
259
+ # Log a successful SSL connect.
260
+ def on_ssl_connected(parms)
261
+ begin
262
+ @log.debug "SSL Connected Parms #{info(parms)}"
263
+ rescue
264
+ @log.debug "SSL Connected oops #{$!}"
265
+ end
266
+ end
267
+
268
+ # Log an unsuccessful SSL connect.
269
+ def on_ssl_connectfail(parms)
270
+ begin
271
+ @log.debug "SSL Connect Fail Parms #{info(parms)}"
272
+ @log.debug "SSL Connect Fail Exception #{parms[:ssl_exception]}, #{parms[:ssl_exception].message}"
273
+ rescue
274
+ @log.debug "SSL Connect Fail oops #{$!}"
275
+ end
276
+ =begin
277
+ # An example LoggerConnectionError raise
278
+ @log.debug "SSL Connect Fail, will raise"
279
+ raise Stomp::Error::LoggerConnectionError.new("quit from SSL connect")
280
+ =end
281
+ end
282
+
283
+ # Log heart beat fires
284
+ def on_hbfire(parms, srind, firedata = {})
285
+ begin
286
+ @log.debug "HeartBeat Fire Parms #{info(parms)}"
287
+ @log.debug "HeartBeat Fire Send/Receive #{srind}"
288
+ rescue
289
+ @log.debug "HeartBeat Fire oops #{$!}"
290
+ end
291
+ end
292
+
293
+ private
294
+
295
+ # Example information extract.
296
+ def info(parms)
297
+ #
298
+ # Available in the parms Hash:
299
+ # parms[:cur_host]
300
+ # parms[:cur_port]
301
+ # parms[:cur_login]
302
+ # parms[:cur_passcode]
303
+ # parms[:cur_ssl]
304
+ # parms[:cur_recondelay]
305
+ # parms[:cur_parseto]
306
+ # parms[:cur_conattempts]
307
+ # parms[:cur_failure]
308
+ # parms[:openstat]
309
+ #
310
+ # For the on_ssl_connectfail callback these are also available:
311
+ # parms[:ssl_exception]
312
+ #
313
+ "Host: #{parms[:cur_host]}, Port: #{parms[:cur_port]}, Login: #{parms[:cur_login]}, Passcode: #{parms[:cur_passcode]}, ssl: #{parms[:cur_ssl]}"
314
+ end
315
+ end # of class
316
+
@@ -0,0 +1,76 @@
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 FileSender
20
+ # Initialize.
21
+ def initialize
22
+ end
23
+ # Run example.
24
+ def run
25
+ p [ "pub001", Thread.current ]
26
+ publogger = Slogger::new
27
+ start_time = Time.now.to_f
28
+ fname = ARGV[0]
29
+ puts "PUBF: 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 "PUBF: File size: #{buff.respond_to?(:bytesize) ? buff.bytesize : buff.length}"
36
+ puts "PUBF: File read: #{ppt} seconds"
37
+ file.close
38
+ #
39
+ client_hdrs = {"accept-version" => "1.1",
40
+ "host" => virt_host(),
41
+ }
42
+ client_hash = { :hosts => [
43
+ {:login => login(), :passcode => passcode(),
44
+ :host => host(), :port => port()},
45
+ ],
46
+ :connect_headers => client_hdrs,
47
+ :logger => publogger,
48
+ :reliable => false, ### *NOTE*
49
+ }
50
+ #
51
+ # p [ "ch", client_hash ]
52
+ client = Stomp::Client.new(client_hash)
53
+ qname = ENV['STOMP_DEST'] ? ENV['STOMP_DEST'] : "/queue/a.big.file"
54
+ puts "PUBF: Qname is: #{qname}"
55
+ # Try to gracefully handle files that exceed broker size limits.
56
+ ph = {:presistent => true}
57
+ ph['suppress_content_length'] = 'yes' if suppresscl()
58
+ puts "PUBF: Headers are: #{ph.inspect}"
59
+ begin
60
+ client.publish(qname, buff, ph)
61
+ rescue
62
+ puts "PUBF: exception on publish: #{$!}"
63
+ end
64
+ sleep 0.1
65
+ e = client.poll() # Check for unsolicited messages from broker
66
+ puts "PUBF: unexpected broker message: #{e}" if e
67
+ client.close
68
+ end_time = Time.now.to_f
69
+ ppt = sprintf("%20.6f", end_time - start_time)
70
+ puts "PUBF: File published: #{ppt} seconds"
71
+ end
72
+ end
73
+ #
74
+ e = FileSender.new
75
+ e.run
76
+