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
data/Manifest.txt
CHANGED
@@ -7,14 +7,18 @@ config/hoe.rb
|
|
7
7
|
config/requirements.rb
|
8
8
|
lib/stomp_message.rb
|
9
9
|
lib/stomp_message/version.rb
|
10
|
+
lib/stomp_message/jms_tools.rb
|
10
11
|
lib/stomp_message/stomp_server.rb
|
11
12
|
lib/stomp_message/stomp_statistics_server.rb
|
12
13
|
lib/stomp_message/stomp_z_active_record_server.rb
|
13
14
|
lib/stomp_message/stomp_send_topic.rb
|
14
|
-
lib/stomp_message/stomp_participant.rb
|
15
15
|
lib/stomp_message/message.rb
|
16
16
|
log/debug.log
|
17
17
|
bin/stomp_message_send.rb
|
18
|
+
bin/jms_server_standalone.rb
|
19
|
+
bin/jms_message_send.rb
|
20
|
+
bin/jms_ping.rb
|
21
|
+
bin/jms_topic_listener.rb
|
18
22
|
script/destroy
|
19
23
|
script/generate
|
20
24
|
script/txt2html
|
data/README.txt
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
= Stomp Message
|
1
2
|
A basic package for sending and receiving stomp messages
|
2
3
|
|
3
4
|
Active Record Server Class
|
@@ -29,4 +30,70 @@ IMPORTANT apachemq or some other messaging platform must be running :)
|
|
29
30
|
puts "#{m.to_s}"
|
30
31
|
msg=StompMessage::Message.load_xml(m)
|
31
32
|
assert msg.command== 'stomp_REPLY', "command wrong"
|
32
|
-
}
|
33
|
+
}
|
34
|
+
|
35
|
+
JRUBY
|
36
|
+
Scotts-Computer:~/Documents/ror/checkouts/stomp_message scott$ cp /Users/scott/Documents/ror/glassfish/jruby/jruby-1_0_3/jruby-1.0.3/lib/asm-
|
37
|
+
asm-2.2.3.jar asm-commons-2.2.3.jar
|
38
|
+
Scotts-Computer:~/Documents/ror/checkouts/stomp_message scott$ cp /Users/scott/Documents/ror/glassfish/jruby/jruby-1_0_3/jruby-1.0.3/lib/asm*.jar build
|
39
|
+
Scotts-Computer:~/Documents/ror/checkouts/stomp_message scott$ cp /Users/scott/Documents/ror/glassfish/jruby/jruby-1_0_3/jruby-1.0.3/lib/backport-util-concurrent.jar build
|
40
|
+
Scotts-Computer:~/Documents/ror/checkouts/stomp_message scott$ cp /Users/scott/Documents/ror/glassfish/jruby/jruby-1_0_3/jruby-1.0.3/lib/jline-0.9.91.jar build
|
41
|
+
Scotts-Computer:~/Documents/ror/checkouts/stomp_message scott$ cp /Users/scott/Documents/ror/glassfish/jruby/jruby-1_0_3/jruby-1.0.3/lib/jruby build
|
42
|
+
jruby-complete.jar jruby.jar
|
43
|
+
Scotts-Computer:~/Documents/ror/checkouts/stomp_message scott$ cp /Users/scott/Documents/ror/glassfish/jruby/jruby-1_0_3/jruby-1.0.3/lib/jruby.jar build
|
44
|
+
Scotts-Computer:~/Documents/ror/checkouts/stomp_message scott$ cp /Users/scott/Documents/ror/glassfish/jruby/jruby-1_0_3/jruby-1.0.3/lib/mysql-connector-java-5.0.8-bin.jar build
|
45
|
+
Scotts-Computer:~/Documents/ror/checkouts/stomp_message scott$ ls build
|
46
|
+
asm-2.2.3.jar jline-0.9.91.jar
|
47
|
+
asm-commons-2.2.3.jar jruby.jar
|
48
|
+
backport-util-concurrent.jar mysql-connector-java-5.0.8-bin.jar
|
49
|
+
com
|
50
|
+
BUILD JAR FILE
|
51
|
+
cd build
|
52
|
+
jar cf ../ficonab.jar .
|
53
|
+
|
54
|
+
#COMPILING:
|
55
|
+
javac -cp $JRUBY_HOME/lib/jruby.jar:$GLASSFISH_ROOT/lib/j2ee.jar -d build com/ficonab/FiconabBase.java
|
56
|
+
javac -cp $JRUBY_HOME/lib/jruby.jar:$GLASSFISH_ROOT/lib/j2ee.jar:./build -d build com/ficonab/MessageBean.java
|
57
|
+
#BUILD JAR FILE
|
58
|
+
cd build
|
59
|
+
jar cf ../ficonab.ear .
|
60
|
+
#INSTALL
|
61
|
+
cd ..
|
62
|
+
asadmin deploy ficonab.ear
|
63
|
+
asadmin deploy --host svbalance.cure.com.ph --port 2626 ficonab.ear
|
64
|
+
|
65
|
+
AUTODEPLOY
|
66
|
+
cp ficonab.jar ../../glassfish/domains/domain1/autodeploy/
|
67
|
+
|
68
|
+
|
69
|
+
war file.
|
70
|
+
jar cf smsapp.war -C tmp/war .
|
71
|
+
|
72
|
+
jar cf ../ficonab.jar .
|
73
|
+
|
74
|
+
IMPORTANT
|
75
|
+
Jdbc pools must be non transactional and set to allow non component callers.
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
CLASSPATHS
|
80
|
+
export CLASSPATH=$CLASSPATH:$GLASSFISH_ROOT/lib/j2ee.jar
|
81
|
+
export CLASSPATH=$CLASSPATH:$GLASSFISH_ROOT/lib/appserv-rt.jar
|
82
|
+
export CLASSPATH=$CLASSPATH:$GLASSFISH_ROOT/lib/javaee.jar
|
83
|
+
export CLASSPATH=$CLASSPATH:$GLASSFISH_ROOT/lib/j2ee-svc.jar
|
84
|
+
export CLASSPATH=$CLASSPATH:$GLASSFISH_ROOT/lib/appserv-ee.jar
|
85
|
+
export CLASSPATH=$CLASSPATH:$GLASSFISH_ROOT/lib/activation.jar
|
86
|
+
export CLASSPATH=$CLASSPATH:$GLASSFISH_ROOT/lib/dbschema.jar
|
87
|
+
export CLASSPATH=$CLASSPATH:$GLASSFISH_ROOT/lib/appserv-admin.jar
|
88
|
+
export CLASSPATH=$CLASSPATH:$GLASSFISH_ROOT/lib/install/applications/jmsra/imqjmx.jar
|
89
|
+
export CLASSPATH=$CLASSPATH:$GLASSFISH_ROOT/lib/install/applications/jmsra/imqjmsra.jar
|
90
|
+
|
91
|
+
export CLASSPATH=$CLASSPATH:$GLASSFISH_ROOT/imq/lib/fscontext.jar
|
92
|
+
|
93
|
+
|
94
|
+
Filesystem context:
|
95
|
+
|
96
|
+
CLASSPATH=/Users/scott/Documents/ror/glassfish/lib/install/jmsra/imqjsra.jar:/Users/scott/Documents/ror/glassfish/lib/j2ee.jar:/Users/scott/Documents/ror/glassfish/lib/appserv-rt.jar:/Users/scott/Documents/ror/glassfish/lib/javaee.jar:/Users/scott/Documents/ror/glassfish/lib/j2ee-svc.jar:/Users/scott/Documents/ror/glassfish/lib/appserv-ee.jar:/Users/scott/Documents/ror/glassfish/lib/install/applications/jmsra/imqjmsra.jar:/Users/scott/Documents/ror/glassfish/lib/install/applications/jmsra/imqjmx.jar:/Users/scott/Documents/ror/glassfish/lib/install/applications/jmsra/imqbroker.jar:/Users/scott/Documents/ror/glassfish/lib/dbschema.jar:/Users/scott/Documents/ror/glassfish/lib/appserv-admin.jar
|
97
|
+
|
98
|
+
|
99
|
+
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/env jruby -S
|
2
|
+
# == Synopsis
|
3
|
+
# Send a message to a jms server and wait for result if requested
|
4
|
+
# == Usage
|
5
|
+
# jms_message_send.rb -T topic -M command -b body -h host -p port "
|
6
|
+
# Debug: to turn on debug: stomp_message_send.rb -T '/topic/sms' -M stomp_DEBUG -b nil
|
7
|
+
# Statistics: stomp_message_send.rb -T '/topic/sms' -M stomp_REPORT -b nil -A true
|
8
|
+
# Reconnect: stomp_message_send.rb -T '/topic/sms' -M stomp_RECONNECT -b nil -A true ---- NOT USED OFTEN
|
9
|
+
# Ping: for ping test: stomp_message_send.rb -T '/topic/sms' -M stomp_PING -b nil -A true
|
10
|
+
# Ping: for email ping test: stomp_message_send.rb -T '/topic/sms' -M stomp_PING -b nil -A true -D comma_separated_email_addresses"
|
11
|
+
# Note -a flag for response --- eg true or false
|
12
|
+
# == Useful commands
|
13
|
+
# jruby -S jms_message_send.rb -M stomp_PING -b nil -A true -T sms
|
14
|
+
# jruby -S jms_message_send.rb -M stomp_DEBUG -b nil -d -T sms
|
15
|
+
# jruby -S jms_message_send.rb -M stomp_REPORT -b nil -A true -D email@com -T sms
|
16
|
+
# == Author
|
17
|
+
# Scott Sproule --- Ficonab.com (scott.sproule@ficonab.com)
|
18
|
+
# == Copyright
|
19
|
+
# Copyright (c) 2007 Ficonab Pte. Ltd.
|
20
|
+
# See license for license details
|
21
|
+
require 'yaml'
|
22
|
+
require 'rubygems'
|
23
|
+
gem 'stomp'
|
24
|
+
require 'stomp'
|
25
|
+
require 'optparse'
|
26
|
+
gem 'stomp_message'
|
27
|
+
require 'stomp_message'
|
28
|
+
require 'rdoc/usage'
|
29
|
+
require 'java'
|
30
|
+
include StompMessage::JmsTools
|
31
|
+
#Hashtable=java.util.Hashtable
|
32
|
+
#Context=javax.naming.Context
|
33
|
+
#InitialContext = javax.naming.InitialContext
|
34
|
+
#Session = javax.jms.Session
|
35
|
+
|
36
|
+
|
37
|
+
arg_hash=StompMessage::Options.parse_options(ARGV)
|
38
|
+
RDoc::usage if arg_hash[:topic]==nil || arg_hash[:command]==nil || arg_hash[:help]==true
|
39
|
+
require 'pp'
|
40
|
+
options = arg_hash
|
41
|
+
# set up variables using hash
|
42
|
+
|
43
|
+
jms_start("TopicConnectionFactory")
|
44
|
+
jms_set_debug(arg_hash[:debug])
|
45
|
+
tdest, tconn= jms_create_destination_connection( arg_hash[:topic])
|
46
|
+
tproducer, tsession= jms_create_producer_session(tdest,tconn)
|
47
|
+
tconsumer, consumer_session = jms_create_consumer_session(tdest,tconn)
|
48
|
+
msg=StompMessage::Message.new(options[:command],options[:body])
|
49
|
+
# msg=StompMessage::Message(arg_hash[:command],'hello body there')
|
50
|
+
count = arg_hash[:count]==nil ? 1 : arg_hash[:count].to_i
|
51
|
+
|
52
|
+
result =jms_send_ack(tsession,tproducer,msg.to_xml)
|
53
|
+
# consumer_session.close
|
54
|
+
puts "#{result}"
|
55
|
+
# sleep(1)
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
puts '-------------finished processing!!!'
|
60
|
+
# sleep(15)
|
61
|
+
# puts "producer id #{producer.getProducerID}"
|
62
|
+
jms_shutdown(tdest, tconn, tsession, tproducer, tconsumer )
|
63
|
+
StompMessage::StompSendTopic.send_email_stomp("scott.sproule@cure.com.ph","STOMP MSG", options[:email],
|
64
|
+
"#{options[:topic]}: #{msg.command}", result) if options[:email]!=nil
|
65
|
+
|
66
|
+
|
67
|
+
# Thread.exit
|
68
|
+
exit!
|
69
|
+
|
data/bin/jms_ping.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
#!/usr/bin/env jruby -S
|
2
|
+
# == Synopsis
|
3
|
+
# Send a ping message to a jms server and wait for result
|
4
|
+
# == Usage
|
5
|
+
# jms_ping.rb -T topic -d "
|
6
|
+
# Ping: for ping test: stomp_message_send.rb -T '/topic/sms' -M stomp_PING -b nil -A true
|
7
|
+
# Ping: for email ping test: stomp_message_send.rb -T '/topic/sms' -M stomp_PING -b nil -A true -D comma_separated_email_addresses"
|
8
|
+
# Note -a flag for response --- eg true or false
|
9
|
+
# == Useful commands
|
10
|
+
# jruby -S jms_ping.rb -T sms
|
11
|
+
# jruby -S jms_ping -d -T sms
|
12
|
+
# == Author
|
13
|
+
# Scott Sproule --- Ficonab.com (scott.sproule@ficonab.com)
|
14
|
+
# == Copyright
|
15
|
+
# Copyright (c) 2007 Ficonab Pte. Ltd.
|
16
|
+
# See license for license details
|
17
|
+
require 'yaml'
|
18
|
+
require 'rubygems'
|
19
|
+
gem 'stomp'
|
20
|
+
require 'stomp'
|
21
|
+
require 'optparse'
|
22
|
+
gem 'stomp_message'
|
23
|
+
require 'stomp_message'
|
24
|
+
require 'rdoc/usage'
|
25
|
+
require 'java'
|
26
|
+
include StompMessage::JmsTools
|
27
|
+
#Hashtable=java.util.Hashtable
|
28
|
+
#Context=javax.naming.Context
|
29
|
+
#InitialContext = javax.naming.InitialContext
|
30
|
+
#Session = javax.jms.Session
|
31
|
+
|
32
|
+
|
33
|
+
arg_hash=StompMessage::Options.parse_options(ARGV)
|
34
|
+
RDoc::usage if arg_hash[:topic]==nil || arg_hash[:help]==true
|
35
|
+
require 'pp'
|
36
|
+
options = arg_hash
|
37
|
+
# set up variables using hash
|
38
|
+
|
39
|
+
jms_start("TopicConnectionFactory")
|
40
|
+
jms_set_debug(arg_hash[:debug])
|
41
|
+
tdest, tconn= jms_create_destination_connection( arg_hash[:topic])
|
42
|
+
tproducer, tsession= jms_create_producer_session(tdest,tconn)
|
43
|
+
tconsumer, consumer_session = jms_create_consumer_session(tdest,tconn)
|
44
|
+
msg=StompMessage::Message.new('stomp_PING',"#{Time.now}")
|
45
|
+
# msg=StompMessage::Message(arg_hash[:command],'hello body there')
|
46
|
+
|
47
|
+
result =jms_send_ack(tsession,tproducer,msg.to_xml)
|
48
|
+
# consumer_session.close
|
49
|
+
puts "#{result}"
|
50
|
+
# sleep(1)
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
puts '-------------finished processing!!!'
|
55
|
+
# sleep(15)
|
56
|
+
# puts "producer id #{producer.getProducerID}"
|
57
|
+
jms_shutdown(tdest, tconn, tsession, tproducer, tconsumer )
|
58
|
+
|
59
|
+
|
60
|
+
# Thread.exit
|
61
|
+
exit!
|
62
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# == Synopsis
|
3
|
+
# jruby -S jms_server_standalone.rb -T topic
|
4
|
+
# start up the server standalone. This is the key component for listening to subscription message
|
5
|
+
# == Usage
|
6
|
+
# jruby -S jms_server_standalone.rb -T test
|
7
|
+
# == Author
|
8
|
+
# Scott Sproule --- Ficonab.com (scott.sproule@ficonab.com)
|
9
|
+
# == Copyright
|
10
|
+
# Copyright (c) 2007 Ficonab Pte. Ltd.
|
11
|
+
# See license for license details
|
12
|
+
|
13
|
+
require 'yaml'
|
14
|
+
require 'rubygems'
|
15
|
+
gem 'stomp'
|
16
|
+
require 'stomp'
|
17
|
+
require 'optparse'
|
18
|
+
gem 'stomp_message'
|
19
|
+
require 'stomp_message'
|
20
|
+
require 'rdoc/usage'
|
21
|
+
require 'java'
|
22
|
+
include StompMessage::JmsTools
|
23
|
+
# env_setting = ARGV[1] || "production"
|
24
|
+
# path_setting = ARGV[0] || "/opt/local/rails_apps/subscriptions/current/"
|
25
|
+
arg_hash=StompMessage::Options.parse_options(ARGV)
|
26
|
+
RDoc::usage if arg_hash[:topic]==nil || arg_hash[:help]==true
|
27
|
+
require 'pp'
|
28
|
+
options = arg_hash
|
29
|
+
@my_topic = arg_hash[:topic]
|
30
|
+
# set up variables using hash
|
31
|
+
|
32
|
+
jms_start("TopicConnectionFactory")
|
33
|
+
jms_set_debug(arg_hash[:debug])
|
34
|
+
tdest, tconn= jms_create_destination_connection( arg_hash[:topic])
|
35
|
+
tproducer, tsession= jms_create_producer_session(tdest,tconn)
|
36
|
+
tconsumer, consumer_session = jms_create_consumer_session(tdest,tconn)
|
37
|
+
|
38
|
+
# begin
|
39
|
+
topic=arg_hash[:topic]
|
40
|
+
s=StompMessage::StompServer.new({:topic => "#{topic}", :standalone => 'true', :jms_source => 'msgserver'})
|
41
|
+
tlistener=StompMessage::MySpecialListener.new(s)
|
42
|
+
tconsumer.setMessageListener(tlistener)
|
43
|
+
#.run
|
44
|
+
# sms_listener.join
|
45
|
+
# rescue Exception => e
|
46
|
+
# puts "exception found #{e.backtrace}"
|
47
|
+
# end
|
48
|
+
|
49
|
+
|
50
|
+
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#!/usr/bin/env jruby -S
|
2
|
+
# == Synopsis
|
3
|
+
# Listen to topic and print it out.... ctrl -c to end
|
4
|
+
# == Usage
|
5
|
+
# jms_message_send.rb -T topic
|
6
|
+
# == Useful commands
|
7
|
+
# jruby -S jms_topic_listener.rb -T sms
|
8
|
+
# == Author
|
9
|
+
# Scott Sproule --- Ficonab.com (scott.sproule@ficonab.com)
|
10
|
+
# == Copyright
|
11
|
+
# Copyright (c) 2007 Ficonab Pte. Ltd.
|
12
|
+
# See license for license details
|
13
|
+
require 'yaml'
|
14
|
+
require 'rubygems'
|
15
|
+
gem 'stomp'
|
16
|
+
require 'stomp'
|
17
|
+
require 'optparse'
|
18
|
+
gem 'stomp_message'
|
19
|
+
require 'stomp_message'
|
20
|
+
require 'rdoc/usage'
|
21
|
+
require 'java'
|
22
|
+
include StompMessage::JmsTools
|
23
|
+
#Hashtable=java.util.Hashtable
|
24
|
+
#Context=javax.naming.Context
|
25
|
+
#InitialContext = javax.naming.InitialContext
|
26
|
+
#Session = javax.jms.Session
|
27
|
+
|
28
|
+
|
29
|
+
arg_hash=StompMessage::Options.parse_options(ARGV)
|
30
|
+
RDoc::usage if arg_hash[:topic]==nil || arg_hash[:help]==true
|
31
|
+
require 'pp'
|
32
|
+
options = arg_hash
|
33
|
+
@my_topic = arg_hash[:topic]
|
34
|
+
# set up variables using hash
|
35
|
+
class MySpecialListener
|
36
|
+
include javax.jms.MessageListener if RUBY_PLATFORM =~ /java/
|
37
|
+
def set_self(meth)
|
38
|
+
@to_call=meth
|
39
|
+
end
|
40
|
+
def onMessage(msg)
|
41
|
+
#puts "----> consumer in on msg #{msg.inspect}"
|
42
|
+
puts "message received #{@my_topic} msg: #{msg.inspect}"
|
43
|
+
# puts "<--- consumer on message"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
jms_start("TopicConnectionFactory")
|
47
|
+
jms_set_debug(arg_hash[:debug])
|
48
|
+
tdest, tconn= jms_create_destination_connection( arg_hash[:topic])
|
49
|
+
tproducer, tsession= jms_create_producer_session(tdest,tconn)
|
50
|
+
tconsumer, consumer_session = jms_create_consumer_session(tdest,tconn)
|
51
|
+
tlistener=MySpecialListener.new
|
52
|
+
tconsumer.setMessageListener(tlistener)
|
53
|
+
puts "listener set"
|
54
|
+
while true
|
55
|
+
sleep(0.25)
|
56
|
+
end
|
57
|
+
# consumer_session.close
|
58
|
+
#puts "#{result}"
|
59
|
+
# sleep(1)
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
puts '-------------finished processing!!!'
|
64
|
+
# sleep(15)
|
65
|
+
# puts "producer id #{producer.getProducerID}"
|
66
|
+
jms_shutdown(tdest, tconn, tsession, tproducer, tconsumer )
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
# Thread.exit
|
71
|
+
exit!
|
72
|
+
|
data/bin/stomp_message_send.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
1
2
|
# == Synopsis
|
2
3
|
# Send a message to a stomp server and wait for result if requested
|
3
4
|
# == Usage
|
@@ -34,7 +35,8 @@ require 'pp'
|
|
34
35
|
options = arg_hash
|
35
36
|
# set up variables using hash
|
36
37
|
msg_sender=StompMessage::StompSendTopic.new(options)
|
37
|
-
msg_sender.
|
38
|
+
msg_sender.jms_set_debug(true) if arg_hash[:debug]
|
39
|
+
#msg_sender.setup_auto_close if !msg_sender.java?
|
38
40
|
m=StompMessage::Message.new(options[:command],options[:body])
|
39
41
|
puts "message is: #{m.to_xml}"
|
40
42
|
# billing_sender.send_topic(m.body, arg_hash[:msisdn])
|
@@ -45,38 +47,17 @@ require 'pp'
|
|
45
47
|
msg_data=nil
|
46
48
|
case options[:ack].downcase
|
47
49
|
when 'true'
|
48
|
-
|
49
|
-
puts 'MESSAGE RECEIVED ----'
|
50
|
-
msg_received_flag=true
|
51
|
-
msg_data=msg
|
52
|
-
puts "handle action block msg is #{msg.to_s}" }
|
53
|
-
begin
|
54
|
-
Timeout::timeout(100) {
|
55
|
-
while true
|
56
|
-
putc '.'
|
57
|
-
exit(0) if msg_received_flag
|
58
|
-
sleep(1)
|
59
|
-
end }
|
60
|
-
rescue SystemExit
|
61
|
-
|
62
|
-
rescue Exception => e
|
63
|
-
puts "exception #{e.message} class: #{e.class}"
|
64
|
-
puts "no receipt"
|
65
|
-
# raise "timeout"
|
66
|
-
#ensure
|
67
|
-
# msg_sender.setup_auto_close
|
68
|
-
end
|
69
|
-
|
70
|
-
|
50
|
+
msg_data= msg_sender.send_topic_ack(m,header,50)
|
71
51
|
else
|
72
52
|
msg_sender.send_topic(m,header)
|
73
53
|
|
74
54
|
end
|
75
55
|
|
76
56
|
msg_sender.send_email_stomp("scott.sproule@cure.com.ph","STOMP MSG", options[:email],
|
77
|
-
m.command, msg_data) if msg_received_flag and options[:email]!=nil
|
57
|
+
"#{options[:topic]}: #{m.command}", msg_data) if msg_received_flag and options[:email]!=nil
|
78
58
|
|
79
|
-
|
59
|
+
msg_sender.send_topic_jms_shutdown if msg_sender.java?
|
80
60
|
|
81
61
|
puts '-------------finished processing!!!'
|
62
|
+
exit!
|
82
63
|
|
@@ -0,0 +1,315 @@
|
|
1
|
+
if RUBY_PLATFORM =~ /java/
|
2
|
+
require 'java'
|
3
|
+
#module Java
|
4
|
+
#include_class 'java.lang.String'
|
5
|
+
#end
|
6
|
+
import java.util.Hashtable
|
7
|
+
import javax.naming.Context
|
8
|
+
import javax.naming.InitialContext
|
9
|
+
import javax.jms.Message
|
10
|
+
import javax.jms.MessageListener
|
11
|
+
import javax.jms.Session
|
12
|
+
import javax.jms.ConnectionFactory
|
13
|
+
import javax.jms.TopicConnectionFactory
|
14
|
+
#import javax.jms.MessageListener
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
module StompMessage
|
19
|
+
module JmsTools
|
20
|
+
|
21
|
+
class MyListener
|
22
|
+
include javax.jms.MessageListener if RUBY_PLATFORM =~ /java/
|
23
|
+
def set_self(meth)
|
24
|
+
@to_call=meth
|
25
|
+
end
|
26
|
+
def onMessage(msg)
|
27
|
+
#puts "----> consumer in on msg #{msg.inspect}"
|
28
|
+
@to_call.send('jms_on_message',msg)
|
29
|
+
# puts "<--- consumer on message"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
def jms_next_transaction_id
|
33
|
+
puts "--- before trans id #{@transaction_id}" if @JmsTools_debug
|
34
|
+
@my_jms_guard_tx.synchronize {
|
35
|
+
@transaction_id+=1 }
|
36
|
+
puts "--- after increment trans id #{@transaction_id}" if @JmsTools_debug
|
37
|
+
@transaction_id
|
38
|
+
end
|
39
|
+
def define_source_id
|
40
|
+
# maybe should user producer id
|
41
|
+
@source_id=rand*10000 + rand*400+1 #if @source_id==0
|
42
|
+
@source_id=@source_id.to_i.to_s
|
43
|
+
puts "--- source id #{@source_id}" if @JmsTools_debug
|
44
|
+
end
|
45
|
+
def unique_source_id
|
46
|
+
@source_id
|
47
|
+
end
|
48
|
+
def jms_my_id
|
49
|
+
@source_id
|
50
|
+
end
|
51
|
+
|
52
|
+
def jms_set_debug(val)
|
53
|
+
val=false if val==nil
|
54
|
+
@JmsTools_debug = val
|
55
|
+
end
|
56
|
+
def jms_start(factory,src_id=nil)
|
57
|
+
jms_set_debug(false)
|
58
|
+
@my_jms_guard = Mutex.new
|
59
|
+
@my_jms_guard2 = Mutex.new
|
60
|
+
@my_jms_guard3 = Mutex.new
|
61
|
+
@my_jms_guard_tx = Mutex.new
|
62
|
+
# @source_id=0 # DEFINE SOURCE ID IF MULTIPLE INSTANCES
|
63
|
+
@source_id=src_id
|
64
|
+
define_source_id if src_id==nil
|
65
|
+
puts "-----> JMSTools start #{Time.now}" #if @JmsTools_debug
|
66
|
+
jms_kill_logging if !@JmsTools_debug
|
67
|
+
|
68
|
+
@JmsTools_current_id=0
|
69
|
+
properties=Hashtable.new(2)
|
70
|
+
#properties.put(Context::PROVIDER_URL, "iiop://127.0.0.1:3700")
|
71
|
+
#properties.put(Context::INITIAL_CONTEXT_FACTORY, "com.sun.appserv.naming.S1ASCtxFactory")
|
72
|
+
properties.put(Context::PROVIDER_URL, "file:///opt/local/imqobjects")
|
73
|
+
properties.put(Context::INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory")
|
74
|
+
|
75
|
+
@JmsTools_ctx=InitialContext.new(properties)
|
76
|
+
puts "after initial context #{@JmsTools_ctx.inspect}" if @JmsTools_debug
|
77
|
+
@JmsTools_conn_factory=@JmsTools_ctx.lookup(factory)
|
78
|
+
puts "PROBLEM jms_start context: #{@JmsTools_ctx.inspect} factory: #{@JmsTools_conn_factory} " if @JmsTools_ctx==nil || @JmsTools_conn_factory==nil
|
79
|
+
|
80
|
+
temp_tx_id= rand*400+1 # set up random start id
|
81
|
+
@transaction_id=temp_tx_id.to_i
|
82
|
+
@response_block_list = {}
|
83
|
+
puts "<------ ending start #{Time.now}" if @JmsTools_debug
|
84
|
+
|
85
|
+
end
|
86
|
+
def jms_manage_headers(headers)
|
87
|
+
headers.each do |k, value|
|
88
|
+
key=k.to_s
|
89
|
+
if ['correlation-id', 'JMSCorrelationID'].include? key
|
90
|
+
headers['JMSCorrelationID']= value.to_s
|
91
|
+
elsif ['expires', 'JMSExpiration'].include? key
|
92
|
+
headers['JMSExpiration']= value.to_i
|
93
|
+
elsif ['persistent', 'JMSDeliveryMode'].include? key
|
94
|
+
headers['JMSDeliveryMode'] = value ? 2 : 1
|
95
|
+
elsif ['priority', 'JMSPriority'].include? key
|
96
|
+
headers['JMSPriority']= value.to_i
|
97
|
+
# elsif ['reply-to', 'JMSReplyTo'].include? key
|
98
|
+
# headers['JMSReplyTo']= nil
|
99
|
+
elsif ['type', 'JMSType'].include? key
|
100
|
+
headers['JMSType']= value.to_s
|
101
|
+
else #is this the most appropriate thing to do here?
|
102
|
+
headers[key] = value.to_s
|
103
|
+
end
|
104
|
+
end
|
105
|
+
# need to turn off persistence, and reply to fix
|
106
|
+
# if headers['JMSReplyTo']==nil
|
107
|
+
# headers['JMSReplyTo']= @source_id
|
108
|
+
# CHECK headers['reply-to']= @source_id
|
109
|
+
# end
|
110
|
+
headers['JMSOrigin']=unique_source_id.to_s
|
111
|
+
puts " --- headers reply #{ headers['JMSReplyTo']} source #{@source_id} id #{headers['JMSMessageID']}" if @JmsTools_debug
|
112
|
+
puts "--- headers #{headers.to_s}" if @JmsTools_debug
|
113
|
+
headers
|
114
|
+
|
115
|
+
end
|
116
|
+
def jms_kill_logging
|
117
|
+
puts "in disabling logging" if @JmsTools_debug
|
118
|
+
enm=java.util.logging.LogManager.log_manager.logger_names
|
119
|
+
while enm.hasMoreElements do
|
120
|
+
t_logger= java.util.logging.Logger.getLogger(enm.nextElement)
|
121
|
+
puts "logger is: #{t_logger.inspect}" if @JmsTools_debug
|
122
|
+
t_logger.level = java.util.logging.Level::OFF if ENV==nil
|
123
|
+
end
|
124
|
+
enm=nil # free for GC
|
125
|
+
end
|
126
|
+
def jms_persistent
|
127
|
+
1 #2 is persistent
|
128
|
+
end
|
129
|
+
# use the raw flag to get the whole message back
|
130
|
+
def jms_send_ack(session,producer,tmp_text,ttimeout=75, rawflag=false)
|
131
|
+
# scott new comment msg=session.create_text_message
|
132
|
+
jms_temp_result =''
|
133
|
+
@my_jms_guard.synchronize {
|
134
|
+
# jms_next_transaction_id
|
135
|
+
jms_tmp_header={}
|
136
|
+
jms_temp_result=''
|
137
|
+
begin
|
138
|
+
count =0;
|
139
|
+
Timeout::timeout(ttimeout) {
|
140
|
+
tmp_msg_recv_flag=false
|
141
|
+
jms_send_message(session,producer,jms_tmp_header,tmp_text) { |t2msg|
|
142
|
+
#puts "message recieved: #{t2msg.inspect}"
|
143
|
+
temp_m=StompMessage::Message.load_xml(t2msg.get_text())
|
144
|
+
jms_temp_result = temp_m.body
|
145
|
+
jms_temp_result = temp_m if rawflag
|
146
|
+
tmp_msg_recv_flag=true
|
147
|
+
}
|
148
|
+
# sleep(0.05)
|
149
|
+
while true
|
150
|
+
# putc '.'
|
151
|
+
count +=1
|
152
|
+
break if tmp_msg_recv_flag
|
153
|
+
sleeptime=count*0.01
|
154
|
+
count= 5 if count > 100 #don't let count get too big
|
155
|
+
sleep(sleeptime)
|
156
|
+
# puts "----sleeptime is: #{sleeptime} count: #{count}"
|
157
|
+
end
|
158
|
+
}
|
159
|
+
|
160
|
+
rescue Timeout::Error
|
161
|
+
jms_temp_result="timeout waiting for response"
|
162
|
+
end
|
163
|
+
}
|
164
|
+
return jms_temp_result
|
165
|
+
end
|
166
|
+
def jms_send_message(session,producer,initial_headers,txt, &block)
|
167
|
+
@my_jms_guard3.synchronize {
|
168
|
+
msg=session.create_text_message
|
169
|
+
jms_next_transaction_id
|
170
|
+
headers={}
|
171
|
+
# puts "initail headers #{initial_headers.inspect} reply to: #{initial_headers['JMSReplyTo']}"
|
172
|
+
if initial_headers['JMSReplyTo']==nil
|
173
|
+
initial_headers['id']=@transaction_id.to_s
|
174
|
+
else
|
175
|
+
puts "reply message id is #{initial_headers['id']}" if @JmsTools_debug
|
176
|
+
end
|
177
|
+
headers=jms_manage_headers(initial_headers)
|
178
|
+
#msg.setIntProperty("id", next_transaction_id)
|
179
|
+
if block_given?
|
180
|
+
puts "----> adding #{@transaction_id} to my block list msg txt #{txt}" if @JmsTools_debug
|
181
|
+
headers['JMSReplyTo']= unique_source_id
|
182
|
+
@response_block_list[@transaction_id.to_s]=block
|
183
|
+
end
|
184
|
+
headers['JMSOrigin']= unique_source_id.to_s
|
185
|
+
headers.each do |k,v|
|
186
|
+
#key=Java::java.lang.String.new(k.to_s)
|
187
|
+
msg.setStringProperty(k.to_s,v.to_s)
|
188
|
+
end
|
189
|
+
msg.setJMSDeliveryMode(jms_persistent) #2 is persistent
|
190
|
+
msg.set_text(txt)
|
191
|
+
producer.send(msg)
|
192
|
+
msg=nil
|
193
|
+
puts "---> jms_send_message sending #{txt}" if @JmsTools_debug
|
194
|
+
puts " ----> jms_send_message" }
|
195
|
+
|
196
|
+
end
|
197
|
+
def jms_create_producer(session,dest)
|
198
|
+
puts "----> in create producer #{Time.now}" if @JmsTools_debug
|
199
|
+
producer=session.create_producer(dest)
|
200
|
+
puts "<----- returning create producer #{Time.now}" if @JmsTools_debug
|
201
|
+
return producer
|
202
|
+
end
|
203
|
+
def jms_message_for_me(msg)
|
204
|
+
@my_jms_guard2.synchronize {
|
205
|
+
if msg.getStringProperty('JMSReplyTo')==unique_source_id
|
206
|
+
puts "message for ME...YAHOO" if @JmsTools_debug
|
207
|
+
tx_id= msg.getStringProperty('id')
|
208
|
+
# puts "id is #{tx_id} size is: #{@response_block_list.size} inspect #{@response_block_list.inspect}"
|
209
|
+
block=@response_block_list[tx_id.to_s]
|
210
|
+
# puts "calling block for #{tx_id}" if block!=nil
|
211
|
+
block.call(msg) if block!=nil
|
212
|
+
@response_block_list.delete(tx_id.to_s) if block!=nil
|
213
|
+
puts "NO BLOCK FOUND FOR MY MESSAGE #{tx_id}" if block==nil
|
214
|
+
else
|
215
|
+
puts "found message for another person---discard" if @JmsTools_debug
|
216
|
+
end
|
217
|
+
}
|
218
|
+
end
|
219
|
+
def jms_on_message(msg)
|
220
|
+
puts "-----> jms on message" if @JmsTools_debug
|
221
|
+
if msg.getStringProperty('JMSOrigin')!=jms_my_id
|
222
|
+
jms_message_for_me(msg)
|
223
|
+
else
|
224
|
+
puts "received message from myself--- discard" if @JmsTools_debug
|
225
|
+
end
|
226
|
+
puts "<----- jms on message" if @JmsTools_debug
|
227
|
+
end
|
228
|
+
def jms_create_consumer(session,dest)
|
229
|
+
puts "----> in create consumer" if @JmsTools_debug
|
230
|
+
consumer=session.create_consumer(dest)
|
231
|
+
listener=MyListener.new
|
232
|
+
listener.set_self(self)
|
233
|
+
consumer.setMessageListener(listener)
|
234
|
+
@my_conn.start
|
235
|
+
puts "<----- returning create consumer" if @JmsTools_debug
|
236
|
+
return consumer
|
237
|
+
end
|
238
|
+
def jms_create_consumer_session(tdest,cconn)
|
239
|
+
puts "----> in create consumer session" if @JmsTools_debug
|
240
|
+
ctsession = cconn.create_session(false,Session::AUTO_ACKNOWLEDGE) # CHEcK AUTo ACK
|
241
|
+
consumer=ctsession.create_consumer(tdest)
|
242
|
+
listener=MyListener.new
|
243
|
+
listener.set_self(self)
|
244
|
+
consumer.setMessageListener(listener)
|
245
|
+
@my_conn=cconn
|
246
|
+
@my_conn.start
|
247
|
+
puts "<----- returning create consumer session" if @JmsTools_debug
|
248
|
+
return consumer, ctsession
|
249
|
+
end
|
250
|
+
def jms_create_producer_session(tdest,cconn)
|
251
|
+
puts "----> in create producer session #{Time.now}" if @JmsTools_debug
|
252
|
+
session = cconn.create_session(false,Session::AUTO_ACKNOWLEDGE) # CHEcK AUTo ACK
|
253
|
+
producer= session.create_producer(tdest)
|
254
|
+
puts "<----- returning create session #{Time.now}" if @JmsTools_debug
|
255
|
+
return producer, session
|
256
|
+
end
|
257
|
+
def jms_close_producer_session(tprod,tsession)
|
258
|
+
puts "----> in jms close producer session #{Time.now}" if @JmsTools_debug
|
259
|
+
# tsession.commit
|
260
|
+
tprod.close if tprod!=nil
|
261
|
+
tsession.close if tsession!=nil
|
262
|
+
puts "<--- in jms close producer session #{Time.now}" if @JmsTools_debug
|
263
|
+
end
|
264
|
+
def jms_create_destination_connection(name)
|
265
|
+
puts "----> in create destination connection #{Time.now}" if @JmsTools_debug
|
266
|
+
tdest=@JmsTools_ctx.lookup(name)
|
267
|
+
tconn=@JmsTools_conn_factory.create_connection
|
268
|
+
# @my_conn=tconn
|
269
|
+
puts "----- dest #{tdest.inspect} conn #{tconn.inspect}" if @JmsTools_debug
|
270
|
+
puts "<----- destination connection #{Time.now}" if @JmsTools_debug
|
271
|
+
return tdest, tconn
|
272
|
+
end
|
273
|
+
|
274
|
+
def jms_create_session(name)
|
275
|
+
puts "----> in create session #{Time.now}" if @JmsTools_debug
|
276
|
+
dest=@JmsTools_ctx.lookup(name)
|
277
|
+
conn=@JmsTools_conn_factory.create_connection
|
278
|
+
@my_conn=conn
|
279
|
+
# SET CONNECTION PARAMETERS TO OPTIMIZE THROUGHPUT HERE
|
280
|
+
# conn.setStringProperty('imqJMSDeliveryMode','1')
|
281
|
+
# conn.setimqJMSDeliveryMode(jms_persistent)
|
282
|
+
session = conn.create_session(false,Session::AUTO_ACKNOWLEDGE) # CHEcK AUTo ACK
|
283
|
+
# session = conn.create_session(false,Session::DUPS_OK_ACKNOWLEDGE) # CHEcK AUTo ACK
|
284
|
+
# conn.start
|
285
|
+
puts "----- dest #{dest.inspect} conn #{conn.inspect}" if @JmsTools_debug
|
286
|
+
puts "<----- returning create session #{Time.now}" if @JmsTools_debug
|
287
|
+
return dest, conn, session
|
288
|
+
end
|
289
|
+
|
290
|
+
def jms_shutdown(tdest, tconn, tsession, tproducer, tconsumer=nil)
|
291
|
+
puts "----> in shutdown " if @JmsTools_debug
|
292
|
+
#dest.shutdown
|
293
|
+
# puts "shutdown #{dest.methods.join(',').to_s}" if @JmsTools_debug
|
294
|
+
puts "conn: #{tconn.inspect} session #{tsession.inspect} producer #{tproducer.inspect}" if @JmsTools_debug
|
295
|
+
@my_conn=nil
|
296
|
+
tproducer.close if tproducer != nil
|
297
|
+
tconsumer.close if tconsumer != nil
|
298
|
+
|
299
|
+
tsession.close if tsession!=nil
|
300
|
+
tconn.stop if tconn!=nil
|
301
|
+
tconn.close() if tconn!=nil
|
302
|
+
tconn.close if tconn!=nil
|
303
|
+
@JmsTools_ctx.close
|
304
|
+
tdest=tconn=tsession=tproducer= @JmsTools_ctx=nil
|
305
|
+
@response_block_list=nil
|
306
|
+
@my_jms_guard = @my_jms_guard2 = @my_jms_guard3 = @my_jms_guard_tx=nil
|
307
|
+
|
308
|
+
|
309
|
+
# puts "---CLOSED conn: #{tconn.inspect} session #{tsession.inspect} producer #{tproducer.inspect} conn factory: #{@JmsTools_conn_factory}" if @JmsTools_debug
|
310
|
+
puts "<----- returning shutdown " if @JmsTools_debug
|
311
|
+
|
312
|
+
end
|
313
|
+
|
314
|
+
end
|
315
|
+
end
|