stomp_message 0.1.8 → 0.6.3
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.
- data/Manifest.txt +5 -1
- data/README.txt +68 -1
- data/bin/jms_message_send.rb +69 -0
- data/bin/jms_ping.rb +62 -0
- data/bin/jms_server_standalone.rb +50 -0
- data/bin/jms_topic_listener.rb +72 -0
- data/bin/stomp_message_send.rb +7 -26
- data/lib/stomp_message/jms_tools.rb +315 -0
- data/lib/stomp_message/message.rb +23 -11
- data/lib/stomp_message/stomp_send_topic.rb +137 -18
- data/lib/stomp_message/stomp_server.rb +229 -31
- data/lib/stomp_message/stomp_statistics_server.rb +3 -2
- data/lib/stomp_message/stomp_z_active_record_server.rb +79 -12
- data/lib/stomp_message/version.rb +2 -2
- data/script/destroy +0 -0
- data/script/generate +0 -0
- data/script/txt2html +0 -0
- data/test/test_stomp_message.rb +3 -28
- metadata +50 -39
- data/lib/stomp_message/stomp_participant.rb +0 -100
@@ -12,7 +12,7 @@ module StompMessage
|
|
12
12
|
class Options
|
13
13
|
def self.parse_options(params)
|
14
14
|
opts = OptionParser.new
|
15
|
-
|
15
|
+
# puts "argv are #{params}"
|
16
16
|
temp_hash = {}
|
17
17
|
temp_hash[:ack]= 'false' # no ack by default
|
18
18
|
temp_hash[:msisdn] = 'not_defined'
|
@@ -20,13 +20,22 @@ module StompMessage
|
|
20
20
|
opts.on("-h","--host VAL", String) {|val| temp_hash[:host ] = val
|
21
21
|
# puts "host is #{val}"
|
22
22
|
}
|
23
|
-
|
23
|
+
# takes ruby hash code and converts to yaml
|
24
|
+
opts.on("-H","--body_hash VAL", String) {|val| temp=eval(val)
|
25
|
+
temp_hash[:body ] = temp.to_yaml
|
26
|
+
# puts "host is #{val}"
|
27
|
+
}
|
28
|
+
opts.on("-D","--email VAL", String) {|val| temp_hash[:email ] = val
|
29
|
+
temp_hash[:destination]=val }
|
24
30
|
|
25
31
|
opts.on("-p","--port VAL", String) {|val| temp_hash[:port ] = val }
|
32
|
+
opts.on("-c","--count VAL", String) {|val| temp_hash[:count ] = val }
|
33
|
+
opts.on("-r","--repeat VAL", String) {|val| temp_hash[:repeat ] = val }
|
26
34
|
opts.on("-S","--subject VAL", String) {|val| temp_hash[:subject ] = val }
|
27
35
|
opts.on("-s","--source VAL", String) {|val| temp_hash[:source ] = val }
|
28
36
|
opts.on("-A","--ack VAL", String) {|val| temp_hash[:ack ] = val
|
29
|
-
|
37
|
+
temp_hash[:action]=val
|
38
|
+
# puts "ack is #{val}"
|
30
39
|
}
|
31
40
|
|
32
41
|
opts.on("-u","--user VAL", String) {|val| temp_hash[:user ] = val }
|
@@ -41,12 +50,13 @@ module StompMessage
|
|
41
50
|
puts "keyword is #{val}"
|
42
51
|
keyword_flag=false }
|
43
52
|
opts.on("-m","--msisdn VAL", String) {|val| temp_hash[:msisdn ] = val }
|
44
|
-
|
45
|
-
|
46
|
-
opts.on("-a","--
|
53
|
+
opts.on("-U","--url VAL", String) {|val| temp_hash[:url ] = val }
|
54
|
+
#oops couldnot thinkof another acronym for a
|
55
|
+
opts.on("-a","--account VAL", String) {|val| temp_hash[:account ] = val }
|
47
56
|
|
48
57
|
opts.on("-B","--broadcast VAL", String) {|val| temp_hash[:broadcast ] = val }
|
49
58
|
opts.on("-x","--help", "get help") { |val| temp_hash[:help]=true }
|
59
|
+
opts.on("-v","--value VAL", String) {|val| temp_hash[:value ] = val }
|
50
60
|
|
51
61
|
opts.on("-d","--debug", "turn on debug") { |val| temp_hash[:debug ] = true }
|
52
62
|
|
@@ -153,12 +163,12 @@ module StompMessage
|
|
153
163
|
# puts "load_xml command is #{command}"
|
154
164
|
body=REXML::XPath.first(doc, "//__stomp_msg_body").text
|
155
165
|
# puts "load_xml body is #{body}"
|
156
|
-
|
166
|
+
tt_sms=StompMessage::Message.new(command, body)
|
157
167
|
rescue Exception => e
|
158
168
|
puts "Exception in load xml:#{xml_string}"
|
159
169
|
puts "message #{e.message}"
|
160
170
|
end
|
161
|
-
|
171
|
+
tt_sms
|
162
172
|
end
|
163
173
|
def self.load_xml_new(xml_string)
|
164
174
|
begin
|
@@ -176,8 +186,10 @@ module StompMessage
|
|
176
186
|
end
|
177
187
|
# if a ruby gem file then you need to grab second in caller array
|
178
188
|
def RDoc.usage_no_exit(*args)
|
179
|
-
main_program_file = caller[1].sub(/:\d+$/, '')
|
180
|
-
|
189
|
+
# main_program_file = caller[1].sub(/:\d+$/, '')
|
190
|
+
main_program_file = caller[1].split(':')[0]
|
191
|
+
#puts "main program is #{main_program_file}"
|
192
|
+
# puts " caller is #{caller.inspect}"
|
181
193
|
comment = File.open(main_program_file) do |file|
|
182
194
|
find_comment(file)
|
183
195
|
end
|
@@ -201,4 +213,4 @@ def RDoc.usage_no_exit(*args)
|
|
201
213
|
end
|
202
214
|
formatter = options.formatter.new(options, "")
|
203
215
|
formatter.display_flow(flow)
|
204
|
-
end
|
216
|
+
end
|
@@ -5,6 +5,10 @@ require 'stomp'
|
|
5
5
|
require 'net/smtp'
|
6
6
|
require 'net/http'
|
7
7
|
require 'socket'
|
8
|
+
if RUBY_PLATFORM =~ /java/
|
9
|
+
require 'java'
|
10
|
+
end
|
11
|
+
|
8
12
|
|
9
13
|
# This
|
10
14
|
module StompMessage
|
@@ -12,22 +16,56 @@ module StompMessage
|
|
12
16
|
class StompSendTopic
|
13
17
|
attr_accessor :conn, :topic, :host, :port, :login, :password, :url
|
14
18
|
#need to define topic, host properly
|
15
|
-
|
19
|
+
include StompMessage::JmsTools if RUBY_PLATFORM =~ /java/
|
16
20
|
def initialize(options={})
|
17
21
|
# set up variables using hash
|
18
22
|
@close_ok=false
|
19
23
|
init_vars(options)
|
24
|
+
if RUBY_PLATFORM =~ /java/
|
25
|
+
@javaflag= @java_flag=true
|
26
|
+
else
|
27
|
+
@javaflag= @java_flag=false
|
28
|
+
end
|
29
|
+
set_up_jms(options[:topic]) if @javaflag
|
20
30
|
# puts "host is: #{host} port is #{port}"
|
21
31
|
# using url as flag wrong
|
22
32
|
# self.conn = Stomp::Client.new(self.login, self.password, self.host, self.port, false) if self.url ==nil
|
23
|
-
|
24
|
-
|
33
|
+
@debug=false
|
34
|
+
|
35
|
+
puts "#{self.class}: Initialized host is: #{self.host} port is #{self.port} topic is #{self.topic} login #{self.login} pass: #{self.password}" if @debug
|
25
36
|
# scott old self.conn.subscribe( self.topic, { :ack =>"auto" }) { |m|
|
26
37
|
# self.conn.subscribe( self.topic, { :ack =>"client" }) { |m|
|
27
38
|
# # puts "#{self.class} msg: #{m.to_s}"
|
28
39
|
# }
|
29
40
|
# setup_auto_close
|
30
41
|
end
|
42
|
+
def jms_msg_result(msg)
|
43
|
+
#tproducer, tsession= self.jms_create_producer_session(@jms_dest,@jms_conn)
|
44
|
+
@my_conn=@jms_conn
|
45
|
+
# tconsumer=jms_create_consumer(tsession,@jms_dest)
|
46
|
+
# tconsumer, consumer_session = self.jms_create_consumer_session(@jms_dest,@jms_conn)
|
47
|
+
# result =jms_send_ack(tsession,tproducer,msg.to_xml)
|
48
|
+
# tsession.commit
|
49
|
+
# tconsumer.close
|
50
|
+
# self.jms_close_producer_session(tproducer, tsession)
|
51
|
+
result =jms_message_handling(@jms_dest, @jms_conn) { jms_send_ack(@session,@producer,msg.to_xml,50) }
|
52
|
+
# self.close_con
|
53
|
+
msg=nil
|
54
|
+
result
|
55
|
+
end
|
56
|
+
def set_up_jms(topic)
|
57
|
+
jms_start("TopicConnectionFactory") #THIS NEEDS TO BE A VAR
|
58
|
+
@jms_dest, @jms_conn = jms_create_destination_connection(topic)
|
59
|
+
# @session = jms_create_session( topic)
|
60
|
+
# @producer = jms_create_producer(@session,@dest)
|
61
|
+
# @consumer = jms_create_consumer(@session,@dest)
|
62
|
+
# at_exit { puts "#{self.class}: auto close exit block" #if @debug
|
63
|
+
# send_topic_jms_shutdown }
|
64
|
+
end
|
65
|
+
def send_topic_jms_shutdown
|
66
|
+
jms_shutdown(@jms_dest, @jms_conn, @session, @producer, @consumer)
|
67
|
+
end
|
68
|
+
|
31
69
|
def init_vars(options)
|
32
70
|
self.login = options[:login]==nil ? '' : options[:login]
|
33
71
|
self.url = options[:url]== nil ? nil : options[:url]
|
@@ -36,14 +74,19 @@ class StompSendTopic
|
|
36
74
|
self.port = options[:port]==nil ? '61613' : options[:port]
|
37
75
|
self.topic = options[:topic]==nil ? '/topic/undefined' : options[:topic]
|
38
76
|
self.conn=nil
|
39
|
-
puts "self url is #{self.url}"
|
77
|
+
puts "self url is #{self.url}" if @debug
|
78
|
+
end
|
79
|
+
def java?
|
80
|
+
@javaflag
|
40
81
|
end
|
41
82
|
# only call this once
|
42
83
|
def setup_auto_close
|
43
84
|
|
44
|
-
at_exit { puts "#{self.class}: auto close exit block"
|
45
|
-
|
46
|
-
|
85
|
+
at_exit { puts "#{self.class}: auto close exit block" if @debug
|
86
|
+
if !self.java?
|
87
|
+
close_topic
|
88
|
+
disconnect_stomp
|
89
|
+
end } if !@close_ok
|
47
90
|
@close_ok=true
|
48
91
|
end
|
49
92
|
#manage timeout etc...
|
@@ -65,7 +108,8 @@ class StompSendTopic
|
|
65
108
|
retry if !flag and count < 4
|
66
109
|
# raise "timeout"
|
67
110
|
|
68
|
-
end
|
111
|
+
end
|
112
|
+
raise 'connection not established' if conn==nil
|
69
113
|
conn
|
70
114
|
end
|
71
115
|
def open_connection
|
@@ -73,14 +117,19 @@ class StompSendTopic
|
|
73
117
|
end
|
74
118
|
# close the topic
|
75
119
|
def close_topic
|
76
|
-
self.conn.unsubscribe(self.topic) if self.conn !=nil
|
120
|
+
self.conn.unsubscribe(self.topic) if self.conn !=nil && !self.java?
|
77
121
|
# self.conn=nil
|
78
122
|
end
|
79
123
|
#disconnect the connection
|
80
124
|
def disconnect_stomp
|
81
|
-
|
82
|
-
|
83
|
-
|
125
|
+
if !self.java?
|
126
|
+
close_topic
|
127
|
+
puts "#{self.class} closing connection #{@jms_conn.inspect}" if @debug
|
128
|
+
@jms_conn.close() if @jms_conn !=nil
|
129
|
+
else
|
130
|
+
@jms_conn.close() if @jms_conn !=nil
|
131
|
+
put "INVESTIGATE THIS diconnect stomp if java in stomp_send_topic.rb"
|
132
|
+
end
|
84
133
|
end
|
85
134
|
# post stomp message to url
|
86
135
|
def post_stomp(msg,headers)
|
@@ -88,26 +137,96 @@ class StompSendTopic
|
|
88
137
|
response_header = {"Content-type" => "text/xml"}
|
89
138
|
response_header.merge headers
|
90
139
|
ht =Net::HTTP.start(self.host,self.port)
|
91
|
-
url = self.url + "/" + self.topic
|
140
|
+
url = self.url # + "/" + self.topic
|
141
|
+
puts "posting to: #{self.host}: #{self.port} #{url} message: #{msg.to_xml}"
|
92
142
|
r=ht.post(url,msg.to_xml,response_header)
|
93
|
-
|
143
|
+
|
94
144
|
puts "result: #{r.to_s}"
|
95
145
|
r
|
96
146
|
end
|
147
|
+
def jms_message_one_way(tjms_dest,tjms_conn)
|
148
|
+
# @my_conn=@jms_conn
|
149
|
+
@producer, @session = self.jms_create_producer_session(tjms_dest,tjms_conn)
|
150
|
+
# tconsumer=jms_create_consumer(@session,@jms_dest)
|
151
|
+
#@producer, @session = self.jms_create_producer_session(tjms_dest,tjms_conn)
|
152
|
+
ttresult = yield
|
153
|
+
# tconsumer.close
|
154
|
+
jms_close_producer_session( @producer, @session )
|
155
|
+
ttresult
|
156
|
+
end
|
157
|
+
def jms_message_handling(tjms_dest,tjms_conn)
|
158
|
+
@my_conn=@jms_conn
|
159
|
+
@producer, @session = self.jms_create_producer_session(tjms_dest,tjms_conn)
|
160
|
+
tconsumer=jms_create_consumer(@session,@jms_dest)
|
161
|
+
#@producer, @session = self.jms_create_producer_session(tjms_dest,tjms_conn)
|
162
|
+
result = yield
|
163
|
+
tconsumer.close
|
164
|
+
jms_close_producer_session( @producer, @session )
|
165
|
+
result
|
166
|
+
end
|
97
167
|
def send_topic(msg, headers, &r_block)
|
98
168
|
# m=StompMessage::Message.new('stomp_BILLING', msg)
|
99
169
|
open_connection
|
100
170
|
more_headers= {'persistent'=>'false' }
|
101
171
|
# i think bug in this merge..needs to return result
|
102
172
|
more_headers.merge headers
|
103
|
-
|
173
|
+
if self.java?
|
174
|
+
jms_message_handling(@jms_dest, @jms_conn) { self.jms_send_message(@session,@producer,headers,msg.to_xml) }
|
175
|
+
else
|
176
|
+
self.conn.send(self.topic, msg.to_xml, more_headers, &r_block)
|
177
|
+
end
|
104
178
|
# Thread.pass
|
105
179
|
end #send_sms
|
180
|
+
def interim_package(msg,headers,timeout)
|
181
|
+
result=false
|
182
|
+
msg_received_flag =false
|
183
|
+
begin
|
184
|
+
Timeout::timeout(timeout+1) {
|
185
|
+
self.send_topic_acknowledge(msg,headers,timeout-1) { |msg| # puts 'in handle action block'
|
186
|
+
# puts "MESSAGE RECEIVED ---- #{msg.to_s} "
|
187
|
+
msg_received_flag=true
|
188
|
+
m=StompMessage::Message.load_xml(msg)
|
189
|
+
result=m.body
|
190
|
+
# result= yield m.body if block_given? FIGURE OUT HOW TO MAKE THIS WORK
|
191
|
+
# puts "result is #{result}"
|
192
|
+
result
|
193
|
+
}
|
194
|
+
|
195
|
+
while true
|
196
|
+
# putc '.'
|
197
|
+
break if msg_received_flag
|
198
|
+
sleep(1)
|
199
|
+
end }
|
200
|
+
rescue SystemExit
|
201
|
+
rescue Timeout::Error
|
202
|
+
rescue Exception => e
|
203
|
+
puts "exception #{e.message} class: #{e.class}"
|
204
|
+
puts "no receipt"
|
205
|
+
end
|
206
|
+
result
|
207
|
+
end
|
208
|
+
def create_consumer
|
209
|
+
@consumer, @consumer_session = jms_create_consumer_session(@jms_dest,@jms_conn)
|
210
|
+
end
|
211
|
+
def send_topic_ack(msg,headers,timeout=75, &r_block)
|
212
|
+
|
213
|
+
result=false
|
214
|
+
#puts "Send topic ack"
|
215
|
+
|
216
|
+
if self.java?
|
217
|
+
#create_consumer if @consumer==nil
|
218
|
+
result =jms_message_handling(@jms_dest, @jms_conn) { jms_send_ack(@session,@producer,msg.to_xml,timeout) }
|
219
|
+
else
|
220
|
+
result =interim_package(msg,headers,timeout)
|
221
|
+
end
|
222
|
+
result
|
223
|
+
# puts "result is now #{result}"
|
224
|
+
end
|
106
225
|
# be careful with the receipt topic calculations... strange errors onactive mq
|
107
|
-
def send_topic_acknowledge(msg, headers, timeout=
|
226
|
+
def send_topic_acknowledge(msg, headers, timeout=60)
|
108
227
|
#m=StompMessage::Message.new('stomp_BILLING', msg)
|
109
228
|
open_connection
|
110
|
-
s=rand*
|
229
|
+
s=rand*30 # scott - used to be 1000 but seem to create connections on activemq
|
111
230
|
# open new topic to listen to reply...
|
112
231
|
# was this but jms seems to blow up receipt_topic="/topic/receipt/client#{s.to_i}"
|
113
232
|
receipt_topic="/topic/rcpt_client#{s.to_i}"
|
@@ -133,7 +252,7 @@ class StompSendTopic
|
|
133
252
|
more_headers= {'persistent'=>'false', 'reply-to' => "#{receipt_topic}" }
|
134
253
|
more_headers.merge headers
|
135
254
|
self.conn.send(self.topic, msg.to_xml, more_headers )
|
136
|
-
Thread.new { sleep(timeout)
|
255
|
+
Thread.new { sleep(timeout+1)
|
137
256
|
puts "calling unsubscribe on #{receipt_topic}" if !receipt_flag
|
138
257
|
self.conn.unsubscribe receipt_topic if !receipt_flag
|
139
258
|
}
|
@@ -1,39 +1,123 @@
|
|
1
1
|
# basic format for stomp messages
|
2
2
|
require 'rexml/document'
|
3
3
|
require 'socket'
|
4
|
+
#require 'monitor'
|
5
|
+
require 'thread'
|
4
6
|
# basic server class for listening to topics
|
5
7
|
module StompMessage
|
8
|
+
class JmsMessage
|
9
|
+
attr_accessor :headers, :body, :command
|
10
|
+
def initialize(body, headers)
|
11
|
+
self.body=body
|
12
|
+
self.headers=headers
|
13
|
+
end
|
14
|
+
end
|
15
|
+
class MySpecialListener
|
16
|
+
include javax.jms.MessageListener if RUBY_PLATFORM =~ /java/
|
17
|
+
def initialize(obj)
|
18
|
+
@call_obj=obj
|
19
|
+
end
|
20
|
+
def set_self(obj)
|
21
|
+
@call_obj=obj
|
22
|
+
end
|
23
|
+
def onMessage(msg)
|
24
|
+
#puts "----> consumer in on msg #{msg.inspect}"
|
25
|
+
puts "message received #{@my_topic}"
|
26
|
+
h= {}
|
27
|
+
msg.get_property_names.each { |n| h[n]=msg.getStringProperty(n) }
|
28
|
+
# puts "text: #{msg.getText()} props: #{h.inspect}"
|
29
|
+
# exit!
|
30
|
+
@call_obj.onMessage(msg.getText(),h)
|
31
|
+
msg=nil
|
32
|
+
h=nil
|
33
|
+
# puts "<--- consumer on message"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
6
37
|
class StompServer
|
7
|
-
|
38
|
+
include StompMessage::JmsTools
|
39
|
+
# include MonitorMixin
|
40
|
+
attr_accessor :conn, :topic, :msg_count, :exception_count, :host, :port, :login, :password, :queue, :thread_count, :mythreads, :guard, :jms_source, :variables, :ss_start_time
|
8
41
|
#need to define topic, host properly
|
9
42
|
@debug=false
|
10
43
|
|
11
44
|
def initialize(options={})
|
45
|
+
self.mythreads = []
|
46
|
+
self.ss_start_time=Time.now
|
47
|
+
puts "VERSION StompServer starting:: #{self.class} #{self.version_number}"
|
48
|
+
if RUBY_PLATFORM =~ /java/
|
49
|
+
@javaflag= @java_flag=true
|
50
|
+
else
|
51
|
+
@javaflag= @java_flag=false
|
52
|
+
end
|
12
53
|
@my_hostname = Socket.gethostname
|
54
|
+
self.guard = Mutex.new
|
55
|
+
self.variables = []
|
56
|
+
# use like self.guard.synchronize { code for synchronize here }
|
13
57
|
self.login = options[:login]==nil ? '' : options[:login]
|
14
|
-
|
58
|
+
self.jms_source = options[:jms_source]==nil ? nil : options[:jms_source]
|
59
|
+
num = options[:thread_count]==nil ? '1' : options[:thread_count]
|
15
60
|
self.thread_count=num.to_i
|
16
61
|
self.password = options[:password]==nil ? '' : options[:password]
|
17
62
|
self.host = options[:host]==nil ? 'localhost' : options[:host]
|
18
63
|
self.port = options[:port]==nil ? '61613' : options[:port]
|
19
64
|
self.topic = options[:topic]==nil ? '/topic/please_define' : options[:topic]
|
20
|
-
|
65
|
+
|
21
66
|
self.msg_count = self.exception_count=0
|
22
|
-
|
23
|
-
|
24
|
-
self.
|
25
|
-
|
67
|
+
|
68
|
+
|
69
|
+
if !self.java?
|
70
|
+
self.queue= Queue.new
|
71
|
+
self.conn=nil
|
72
|
+
|
73
|
+
connect_connection
|
26
74
|
# self.conn = Stomp::Client.new self.login, self.password, self.host, self.port, false
|
27
75
|
# self.conn = Stomp::Connection.open self.login, self.password, self.host , self.port, false
|
28
|
-
|
76
|
+
connect_topic
|
77
|
+
setup_auto_close
|
78
|
+
else
|
79
|
+
do_jms_setup
|
80
|
+
end
|
29
81
|
@debug=false
|
30
|
-
puts "
|
31
|
-
|
82
|
+
puts "#{self.class}: message broker host is: #{host} port is #{port} topic is: #{self.topic} threads #{self.thread_count} my host: #{@my_hostname} jms source #{self.jms_source} java flag #{@javaflag}"
|
83
|
+
puts "VERSION StompServer finalized:: #{self.class} #{self.version_number}"
|
84
|
+
|
32
85
|
trap("INT") { puts "#{Time.now}: #{self.class} in interrupt trap\n"
|
33
86
|
#close_topic
|
34
87
|
#disconnect_stomp
|
35
88
|
#setup_auto_close already done in INIT
|
36
|
-
|
89
|
+
jms_close_connections
|
90
|
+
exit! }
|
91
|
+
|
92
|
+
|
93
|
+
end
|
94
|
+
def java?
|
95
|
+
@javaflag
|
96
|
+
end
|
97
|
+
def version_number
|
98
|
+
module_name=self.class.to_s.split('::')[0]
|
99
|
+
version_num = eval("#{module_name}::VERSION::STRING") #note needs version/string
|
100
|
+
end
|
101
|
+
def create_dest_conn
|
102
|
+
# puts "IN CREATE DEST CONN"
|
103
|
+
@ss_jms_dest, @ss_jms_conn = jms_create_destination_connection(self.topic) if @ss_jms_conn==nil
|
104
|
+
# @ss_jms_conn.start if @ss_jms_conn!=nil
|
105
|
+
# puts " STARTED CONNECTION"
|
106
|
+
# puts "JMS create dest_conn :dest #{@ss_jms_dest.inspect} conn: #{@ss_jms_conn.inspect}"
|
107
|
+
end
|
108
|
+
def create_jms_mdb_connections
|
109
|
+
puts "----> entering jms mdb connections"
|
110
|
+
jms_start("TopicConnectionFactory",self.jms_source) #if @JmsTools_conn_factory==nil
|
111
|
+
create_dest_conn
|
112
|
+
puts "<---- leaving jms mdb connections" # if @debug
|
113
|
+
end
|
114
|
+
def do_jms_setup
|
115
|
+
puts "----> entering jms setup" #if @debug
|
116
|
+
setup_thread_specific_items("#{self.jms_source} thread")
|
117
|
+
create_jms_mdb_connections
|
118
|
+
# jms_auto_close
|
119
|
+
check_thread
|
120
|
+
puts "<---- leaving jms setup" # if @debug
|
37
121
|
end
|
38
122
|
def reconnect
|
39
123
|
puts "about to reconnect"
|
@@ -53,23 +137,70 @@ module StompMessage
|
|
53
137
|
# self.mythreads.each {|t| t.raise "auto exit" }
|
54
138
|
}
|
55
139
|
end
|
140
|
+
def server_shutdown
|
141
|
+
puts "----in server shutdown"
|
142
|
+
end
|
143
|
+
def jms_close_connections
|
144
|
+
puts "----in jms close connections #{self.topic}--HERE BE DRAGONS"
|
145
|
+
# puts "----#{@ss_jms_dest.inspect} #{@ss_jms_conn.inspect} #{@ss_session.inspect} #{@ss_producer.inspect}"
|
146
|
+
@ss_session.close if @ss_session!=nil
|
147
|
+
@ss_producer.close if @ss_producer!=nil
|
148
|
+
@ss_jms_conn.close if @ss_jms_conn!=nil
|
149
|
+
@ss_consumer.close if @ss_consumer!=nil
|
150
|
+
# @ss_session=@ss_producer=@ss_jms_conn=nil
|
151
|
+
server_shutdown
|
152
|
+
object_duration = Time.now - self.ss_start_time
|
153
|
+
puts "---- Duration: #{object_duration} #{self.class} #{self.version_number} on topic #{self.topic}"
|
154
|
+
# puts "----closed session and producer #{@ss_jms_dest.inspect} #{@ss_jms_conn.inspect} #{@ss_session.inspect} #{@ss_producer.inspect}"
|
155
|
+
object_duration=nil
|
156
|
+
puts "----after jms shutdown #{self.topic}--- exiting"
|
157
|
+
#exit!
|
158
|
+
end
|
159
|
+
def check_session #NOT USED
|
160
|
+
|
161
|
+
@ss_producer, @ss_session = jms_create_producer_session(@ss_jms_dest, @ss_jms_conn) if @ss_producer==nil || @ss_session==nil
|
162
|
+
end
|
163
|
+
def jms_auto_close
|
164
|
+
at_exit { puts "#{self.class}: in at exit block"
|
165
|
+
# PERHAPS SET GLOBALBS for dest/conn
|
166
|
+
jms_close_connections
|
167
|
+
# self.mythreads.each {|t| t.raise "auto exit" }
|
168
|
+
}
|
169
|
+
end
|
56
170
|
def disconnect_stomp
|
57
171
|
puts "#{self.class} #{@my_hostname} closing connection"
|
58
172
|
self.conn.close() if self.conn !=nil
|
59
173
|
end
|
174
|
+
|
175
|
+
|
176
|
+
def jms_message_handling(tjms_dest, tjms_conn)
|
177
|
+
#puts "JMS MESSAGE HNDLE #{tjms_dest.inspect} #{tjms_conn.inspect}"
|
178
|
+
@ss_producer, @ss_session = self.jms_create_producer_session(tjms_dest, tjms_conn)
|
179
|
+
# puts "JMS MESSAGE HNDLE sprod #{@ss_producer.inspect} sess #{@ss_session.inspect}"
|
180
|
+
result = yield
|
181
|
+
jms_close_producer_session( @ss_producer, @ss_session )
|
182
|
+
result
|
183
|
+
end
|
60
184
|
def send_reply(headers,msg)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
185
|
+
# if headers['reply-to']!=nil || headers['JMSReplyTo']!=nil
|
186
|
+
reply_topic=headers['reply-to']
|
187
|
+
# create_dest_conn
|
188
|
+
response_header = {'persistent'=>'false'}
|
189
|
+
response_header.merge headers
|
190
|
+
response_header['id']= headers['id']
|
191
|
+
response_header['JMSReplyTo']= headers['JMSReplyTo']
|
192
|
+
# puts "SEND REPLY setting response to #{response_header['JMSReplyTo']} for id #{response_header['id']} "
|
193
|
+
puts "SEND REPLY #{response_header.inspect}" if @debug
|
194
|
+
puts "<----- reply to follow:"
|
195
|
+
if self.java?
|
196
|
+
jms_message_handling(@ss_jms_dest, @ss_jms_conn) { jms_send_message(@ss_session,@ss_producer,headers,msg.to_xml) }
|
197
|
+
|
198
|
+
else
|
199
|
+
self.conn.send(reply_topic, msg.to_xml, response_header )
|
200
|
+
end
|
201
|
+
|
202
|
+
# end
|
203
|
+
|
73
204
|
end
|
74
205
|
# name is message command
|
75
206
|
def connect_topic
|
@@ -96,23 +227,37 @@ module StompMessage
|
|
96
227
|
self.conn.unsubscribe self.topic if self.conn!=nil
|
97
228
|
end
|
98
229
|
def stomp_PING(msg,stomp_msg)
|
99
|
-
body="ALIVE Class: #{self.class.to_s}
|
230
|
+
body="ALIVE Class: #{self.class.to_s} id: #{self.object_id} listening to: #{self.topic} on host #{@my_hostname} id thread #{Thread.current.inspect} msg_count #{self.msg_count} exception_count #{self.exception_count} time: #{Time.now}\n"
|
231
|
+
body << "Object details #{self.inspect}" if @debug
|
100
232
|
reply_msg = StompMessage::Message.new('stomp_REPLY', body)
|
101
|
-
|
233
|
+
[true, reply_msg]
|
234
|
+
|
235
|
+
end
|
236
|
+
def check_thread
|
237
|
+
if @debug
|
238
|
+
puts "----check thread id: #{get_id} Thread value: #{Thread.current.inspect} "
|
239
|
+
self.variables[get_id].each { |key, val|
|
240
|
+
puts "---- key #{key} is: #{val.inspect}"}
|
241
|
+
end
|
102
242
|
end
|
103
243
|
def stomp_RECONNECT(msg,stomp_msg)
|
104
244
|
reconnect
|
105
|
-
|
245
|
+
|
246
|
+
body="ALIVE Class: #{self.class.to_s} listing to: #{self.topic} on host #{@my_hostname} msg_count #{self.msg_count} exception_count #{self.exception_count} id #{self.inspect} thread #{Thread.current.inspect} connection status #{self.conn.open?}"
|
106
247
|
reply_msg = StompMessage::Message.new('stomp_REPLY', body)
|
107
|
-
|
248
|
+
[true, reply_msg]
|
249
|
+
|
108
250
|
end
|
109
251
|
def stomp_DEBUG(msg,stomp_msg)
|
252
|
+
|
110
253
|
@debug=!@debug
|
111
254
|
puts "debug flag is now #{@debug}"
|
255
|
+
[false, ""]
|
112
256
|
end
|
113
257
|
def method_missing(name, *args)
|
114
258
|
puts "Method missing called: #{name}"
|
115
259
|
puts "Likely invalid message recieved"
|
260
|
+
[false, ""]
|
116
261
|
end
|
117
262
|
# monitor queue
|
118
263
|
def monitor_queue_status
|
@@ -139,7 +284,7 @@ module StompMessage
|
|
139
284
|
result << "ALIVE Class: #{self.class.to_s} listing to: #{self.topic} on host #{@my_hostname} msg_count #{self.msg_count} exception_count #{self.exception_count}\n"
|
140
285
|
result << "-----exception data--------\n"
|
141
286
|
result << " Thread: #{Thread.current[:name]} :exception found #{e.backtrace}\n"
|
142
|
-
result << "Thread: #{Thread.current[:name]} :exception messag #{e.message}"
|
287
|
+
result << "Thread: #{Thread.current[:name]} :exception messag #{e.message} e: #{e.inspect}"
|
143
288
|
begin
|
144
289
|
StompMessage::StompSendTopic.send_email_stomp("scott.sproule@cure.com.ph",
|
145
290
|
"STOMP EXCEPTION", "scott.sproule@cure.com.ph","Thread: #{Thread.current[:name]} :exception messag #{e.message}", result)
|
@@ -147,20 +292,73 @@ module StompMessage
|
|
147
292
|
puts "Can not send email, please check smtp host setting"
|
148
293
|
end
|
149
294
|
end
|
295
|
+
def check_origin(thash)
|
296
|
+
flag= false
|
297
|
+
src_id = thash['JMSOrigin']
|
298
|
+
flag= src_id.to_s!=self.jms_source if src_id!=nil
|
299
|
+
#puts "ORIGIN FLAG #{flag}"
|
300
|
+
flag
|
301
|
+
end
|
302
|
+
def onMessage(msg_body,msg_hash)
|
303
|
+
puts "message body is : #{msg_body} hash #{msg_hash}" if @debug
|
304
|
+
puts "my id is #{jms_my_id} message id is #{msg_hash['JMSOrigin']}" if @debug
|
305
|
+
start_time=Time.now
|
306
|
+
if check_origin(msg_hash)
|
307
|
+
begin
|
308
|
+
self.msg_count+=1
|
309
|
+
check_thread if @debug
|
310
|
+
m=StompMessage::Message.load_xml(msg_body)
|
311
|
+
puts "----> #{Time.now} received msg is #{m.command}" # if @debug
|
312
|
+
msg=StompMessage::JmsMessage.new(msg_body,msg_hash)
|
313
|
+
puts "jms message: #{msg.inspect}" if @debug
|
314
|
+
|
315
|
+
r=send(m.command, m, msg)
|
316
|
+
duration=Time.now-start_time
|
317
|
+
puts "--- Message processing before reply: #{self.topic}: #{m.command} : #{duration}"
|
318
|
+
send_reply(msg.headers,r[1]) if r[0]==true
|
319
|
+
duration=Time.now-start_time
|
320
|
+
|
321
|
+
puts "--- Message processed #{self.topic}: #{m.command} : #{duration}"
|
322
|
+
m=nil
|
323
|
+
rescue Exception => e
|
324
|
+
self.exception_count+=1
|
325
|
+
handle_exception(e)
|
326
|
+
end
|
327
|
+
else
|
328
|
+
puts "----> received message from myself...ignoring #{msg_hash['JMSOrigin']}"
|
329
|
+
end #JMS Origin if
|
330
|
+
msg_body=msg_hash=nil
|
331
|
+
puts "<-----finished onMesage"
|
332
|
+
# puts "Message is: #{m.to_xml}" if @debug
|
333
|
+
# effectively case statement (Should SCREEN HERE)
|
334
|
+
# puts "sms text is: #{sms.text} dest is: #{sms.destination} result is: #{res}"
|
335
|
+
end
|
150
336
|
def handle_message(msg)
|
151
337
|
puts "STOMP message frame is : #{msg} " if @debug
|
152
338
|
m=StompMessage::Message.load_xml(msg.body)
|
153
339
|
# puts "Message is: #{m.to_xml}" if @debug
|
154
340
|
puts "Message type is #{m.command}" if @debug
|
155
|
-
send(m.command, m, msg)
|
341
|
+
r=send(m.command, m, msg)
|
342
|
+
send_reply(msg.headers,r[1]) if r[0]=true
|
156
343
|
# puts "sms text is: #{sms.text} dest is: #{sms.destination} result is: #{res}"
|
157
344
|
end
|
158
345
|
#define thread specific variables here
|
159
346
|
# eg Thread.currect[:smsc]=blah blah
|
347
|
+
def get_id
|
348
|
+
id = Thread.current[:id]
|
349
|
+
id = 1 if @java_flag
|
350
|
+
id
|
351
|
+
end
|
160
352
|
def setup_thread_specific_items(mythread_number)
|
161
|
-
|
353
|
+
puts "----> entering setup threads #{mythread_number}" # if @debug
|
162
354
|
Thread.current[:name]= "Thread: #{mythread_number}"
|
163
|
-
|
355
|
+
Thread.current[:id]=mythread_number
|
356
|
+
self.variables[get_id]={}
|
357
|
+
|
358
|
+
#self.variables[get_id][:test_field]='test problem'
|
359
|
+
check_thread
|
360
|
+
puts "<---- leaving setup threads" if @debug
|
361
|
+
|
164
362
|
end
|
165
363
|
def run
|
166
364
|
1.upto(self.thread_count) { |c| # create the threads here
|