stomp_message 0.1.8 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -42,6 +42,7 @@ module StompMessage
42
42
  end
43
43
  def stomp_PING(msg, stomp_msg)
44
44
  puts "stomp PING: #{msg.body}" if @debug
45
+ [false,'']
45
46
  #do not reply as statistic servers do no respond to pings. they respond to stomp_REPORT
46
47
  end
47
48
  #def create_statistics(msg) # k[it]=0 if !k.key?(it)
@@ -68,8 +69,7 @@ module StompMessage
68
69
  }
69
70
  puts result if @debug
70
71
  reply_msg = StompMessage::Message.new('stomp_REPLY', "#{result}")
71
- send_reply(stomp_msg.headers,reply_msg) if stomp_msg.headers['reply-to']!=nil
72
- result
72
+ [true, reply_msg]
73
73
  end
74
74
  def stomp_RESET(msg, stomp_msg)
75
75
  puts "stomp reset: #{msg.body}" if @debug
@@ -78,6 +78,7 @@ module StompMessage
78
78
  self.statistics[reset_tag].each { |k,v| self.statistics[reset_tag][k]=0
79
79
  puts "RESET: tag #{k} value is zero"
80
80
  } if self.tags.include?(msg.body.to_s)
81
+ [false,'']
81
82
  end
82
83
  end
83
84
  end
@@ -1,5 +1,6 @@
1
1
  require 'yaml'
2
2
  require 'erb'
3
+ require 'socket'
3
4
 
4
5
  #require 'stomp_server'
5
6
  module StompMessage
@@ -7,6 +8,7 @@ module StompMessage
7
8
  # had to name it Z due to order problems. not sure why.
8
9
  class StompZActiveRecordServer < StompMessage::StompServer
9
10
  attr_accessor :model_list
11
+ attr_reader :database_env
10
12
  def initialize(options={})
11
13
  super(options)
12
14
  puts "root_path: #{options[:root_path]} rails_environment #{options[:env]}"
@@ -18,15 +20,32 @@ def initialize(options={})
18
20
  #note this is specific tomysql... need to fix later
19
21
  def check_active_record_connection(my_class)
20
22
  begin
21
- conn=my_class.new.connection
22
- puts " checking AR connection status: #{conn.active?}"
23
- puts " AR down... reconnecting" if !conn.active?
23
+ ar_conn=my_class.new.connection
24
+ puts " checking AR connection status: #{ar_conn.active?}"
25
+ puts " AR down... reconnecting" if !ar_conn.active?
24
26
  # puts "after first check"
25
- conn.reconnect! if !conn.active?
27
+ ar_conn.reconnect! if !ar_conn.active?
26
28
  # puts "after reconnect"
27
29
  rescue Mysql::Error
28
30
  puts "reconnecting due to Mysql:Error"
29
- conn.reconnect
31
+ ar_conn.reconnect
32
+ rescue Exception => e
33
+ puts "ActiveRecord found exception that should not be here #{e.message}"
34
+ end
35
+ end
36
+ def check_ar_connection
37
+ begin
38
+ ActiveRecord::Base.establish_connection(self.database_env) if !ActiveRecord::Base.connected?
39
+
40
+ ar_conn=ActiveRecord::Base.connection
41
+ puts " checking AR connection status: #{ar_conn.active?}"
42
+ puts " AR down... reconnecting" if !ar_conn.active?
43
+ # puts "after first check"
44
+ ar_conn.reconnect! if !ar_conn.active?
45
+ # puts "after reconnect"
46
+ rescue Mysql::Error
47
+ puts "reconnecting due to Mysql:Error"
48
+ ar_conn.reconnect
30
49
  rescue Exception => e
31
50
  puts "ActiveRecord found exception that should not be here #{e.message}"
32
51
  end
@@ -43,20 +62,41 @@ def monitor_ar_status(connection)
43
62
  end # while
44
63
  }
45
64
  end
65
+ #RAILS_ENV= 'production' if RUBY_PLATFORM =~ /java/
46
66
  # the model path needs to include the models for active record... can be inferred from
47
67
  # table names if needed but easiest and simplest is to give path to to the rails application
48
- def setup_active_record(root_path,env)
68
+ def setup_active_record(root_path,tenv)
49
69
  require 'rubygems'
70
+ if self.java?
71
+ env = 'development'
72
+ env = 'production' if Socket.gethostname=='svbalance.cure.com.ph'
73
+ env = tenv if tenv!=nil
74
+ end
75
+ # env = 'production' #now using connection pools so always production
76
+ #ENV['RAILS_ENV'] ||= env
77
+ #RAILS_ENV=env
50
78
  gem 'activerecord'
51
79
  require 'active_record'
80
+
81
+ # ENV['RAILS_ENV'] ||= env
82
+ # RAILS_ENV=env
52
83
  path= root_path + "config/database.yml"
53
- puts "path is #{path}"
84
+ puts "path is #{path}" if @debug
54
85
  data=File.open(path).readlines.join
86
+ # puts "file open"
55
87
  result=ERB.new(data).result
88
+ # puts "after erb #{result}"
56
89
  parsed=YAML.load(result)
57
- puts "env is #{env} values are: #{parsed[env]}"
58
- ActiveRecord::Base.establish_connection(parsed[env])
59
- ActiveRecord::Base.logger = Logger.new(STDOUT)
90
+ # puts " values are: #{parsed.to_s}" # if @debug
91
+ puts "env is #{env} values are: #{parsed[env]}" if @debug
92
+
93
+ @database_env=parsed[env]
94
+ # puts "db temp #{self.database_env.to_s}"
95
+ puts "Database settings: #{self.database_env.inspect} from environment #{env} in database.yml"
96
+ puts "JNDI Needed: #{self.database_env['jndi']} please ensure configured!" if self.database_env['jndi'] !=nil
97
+ ActiveRecord::Base.allow_concurrency = true
98
+ establish_ar_jdbc_pool
99
+ ActiveRecord::Base.logger = Logger.new(STDOUT) #RAILS_DEFAULT_LOGGER
60
100
  # grab all the models
61
101
  # model_path = root_path + "app/models/*.rb"
62
102
  load_models(root_path)
@@ -64,6 +104,26 @@ def setup_active_record(root_path,env)
64
104
  end
65
105
  #load the AR models... override if necessary
66
106
  # model list is an array of models to load
107
+ def onMessage(msg_body,msg_hash)
108
+ puts "----> Stomp Z AR on Message"
109
+ if check_origin(msg_hash)
110
+ establish_ar_jdbc_pool
111
+ super(msg_body,msg_hash)
112
+ free_ar_jdbc_pool
113
+ end
114
+ msg_body=msg_hash=nil
115
+ puts "<---- Stomp Z AR on Message exit"
116
+
117
+ end
118
+ def establish_ar_jdbc_pool
119
+ puts "----- establish jdbc pool"
120
+ check_ar_connection
121
+ end
122
+ def free_ar_jdbc_pool
123
+ puts "---- free pool"
124
+ # ActiveRecord::Base.connection.disconnect!
125
+ # ActiveRecord::Base.remove_connection
126
+ end
67
127
  def load_models(root_path)
68
128
  model_path = root_path + "app/models/"
69
129
  # puts "model path is #{model_path}"
@@ -71,11 +131,18 @@ def setup_active_record(root_path,env)
71
131
  self.model_list.each { |model_file|
72
132
  lib = model_path + model_file
73
133
  last_model = require lib
74
- puts "loading required model: is #{lib}"
134
+ puts "loading required model: is #{lib}" if @debug
75
135
  # last_model=lib #last one needs to be active_record (need to fix)
76
136
  }
77
137
  puts "last model is #{last_model}"
78
- monitor_ar_status(eval("#{last_model[0]}"))
138
+ monitor_ar_status(eval("#{last_model[0]}")) if !self.java?
79
139
  end
140
+ def server_shutdown
141
+ puts "---->shutting down AR"
142
+ free_ar_jdbc_pool
143
+ super
144
+ puts "<----shut down AR"
145
+
146
+ end
80
147
  end # class
81
148
  end #module
@@ -1,8 +1,8 @@
1
1
  module StompMessage #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 1
5
- TINY = 8
4
+ MINOR = 6
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/script/destroy CHANGED
File without changes
data/script/generate CHANGED
File without changes
data/script/txt2html CHANGED
File without changes
@@ -1,12 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/test_helper.rb'
2
- class OpenWFE::StompParticipant
3
- def reply_to_engine(workitem)
4
- puts "hello from test reply to engine"
5
- end
6
- end
2
+
7
3
  require 'rubygems'
8
- gem 'openwferu'
9
- require 'openwfe/workitem'
4
+
10
5
  gem 'stomp_message'
11
6
  require 'stomp_message'
12
7
  class TestStompMessage < Test::Unit::TestCase
@@ -202,25 +197,5 @@ class TestStompMessage < Test::Unit::TestCase
202
197
  ss_thread.kill
203
198
  end
204
199
 
205
- def test_stomp_parti
206
- #note activemq or stomp message bus needs to be running
207
- args={}
208
- args[:topic] = '/topic/test'
209
- ss=StompMessage::StompServer.new(args)
210
- ss_thread = Thread.new {
211
- ss.run }
212
- assert ss.topic=='/topic/test', "topic not set properly"
213
- participant=OpenWFE::StompParticipant.new('/topic/test') { puts "hello from block"}
214
- wi = OpenWFE::WorkItem.new()
215
- wi[:command] = 'stomp_PING'
216
- wi[:body] = 'body'
217
- wi[:msisdn] = '63999999'
218
- m2=StompMessage::Message.new(wi[:command].to_s,wi[:body].to_s)
219
- puts "m2: #{m2.to_xml}"
220
- assert m2.to_xml==StompMessage::Message.load_xml(m2.to_xml).to_xml, "problems in wi xml"
221
- wi['sms'] = "hello there"
222
- participant.consume(wi)
223
- ss_thread.kill
224
-
225
- end
200
+
226
201
  end
metadata CHANGED
@@ -1,33 +1,16 @@
1
- --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.4
3
- specification_version: 1
4
- name: stomp_message
5
- version: !ruby/object:Gem::Version
6
- version: 0.1.8
7
- date: 2007-11-05 00:00:00 +08:00
8
- summary: handling stomp messages and servers
9
- require_paths:
10
- - lib
11
- email: scott dot sproule at ficonab dot com
1
+ --- !ruby/object:Gem::Specification
2
+ extensions: []
12
3
  homepage: http://stompmessage.rubyforge.org
13
- rubyforge_project: stompmessage
14
- description: handling stomp messages and servers
15
- autorequire:
16
- default_executable:
17
- bindir: bin
18
- has_rdoc: true
19
- required_ruby_version: !ruby/object:Gem::Version::Requirement
20
- requirements:
21
- - - ">"
22
- - !ruby/object:Gem::Version
23
- version: 0.0.0
24
- version:
25
- platform: ruby
26
- signing_key:
27
- cert_chain:
4
+ executables:
5
+ - stomp_message_send.rb
6
+ - jms_server_standalone.rb
7
+ - jms_message_send.rb
8
+ - jms_ping.rb
9
+ - jms_topic_listener.rb
10
+ version: !ruby/object:Gem::Version
11
+ version: 0.6.3
28
12
  post_install_message:
29
- authors:
30
- - scott sproule
13
+ date: 2008-06-24 16:00:00 +00:00
31
14
  files:
32
15
  - History.txt
33
16
  - License.txt
@@ -38,14 +21,18 @@ files:
38
21
  - config/requirements.rb
39
22
  - lib/stomp_message.rb
40
23
  - lib/stomp_message/version.rb
24
+ - lib/stomp_message/jms_tools.rb
41
25
  - lib/stomp_message/stomp_server.rb
42
26
  - lib/stomp_message/stomp_statistics_server.rb
43
27
  - lib/stomp_message/stomp_z_active_record_server.rb
44
28
  - lib/stomp_message/stomp_send_topic.rb
45
- - lib/stomp_message/stomp_participant.rb
46
29
  - lib/stomp_message/message.rb
47
30
  - log/debug.log
48
31
  - bin/stomp_message_send.rb
32
+ - bin/jms_server_standalone.rb
33
+ - bin/jms_message_send.rb
34
+ - bin/jms_ping.rb
35
+ - bin/jms_topic_listener.rb
49
36
  - script/destroy
50
37
  - script/generate
51
38
  - script/txt2html
@@ -55,22 +42,46 @@ files:
55
42
  - tasks/website.rake
56
43
  - test/test_helper.rb
57
44
  - test/test_stomp_message.rb
58
- test_files:
59
- - test/test_helper.rb
60
- - test/test_stomp_message.rb
45
+ rubygems_version: 1.1.0
61
46
  rdoc_options:
62
47
  - --main
63
48
  - README.txt
49
+ signing_key:
50
+ cert_chain: []
51
+ name: stomp_message
52
+ has_rdoc: true
53
+ platform: ruby
54
+ summary: handling stomp messages and servers
55
+ default_executable:
56
+ bindir: bin
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ version:
59
+ requirements:
60
+ - - '>='
61
+ - !ruby/object:Gem::Version
62
+ version: !str 0
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ version:
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: !str 0
69
+ require_paths:
70
+ - lib
71
+ specification_version: 2
72
+ test_files:
73
+ - test/test_helper.rb
74
+ - test/test_stomp_message.rb
75
+ dependencies: []
76
+ description: handling stomp messages and servers
77
+ email: scott dot sproule at ficonab dot com
78
+ authors:
79
+ - scott sproule
64
80
  extra_rdoc_files:
65
81
  - History.txt
66
82
  - License.txt
67
83
  - Manifest.txt
68
84
  - README.txt
69
- executables:
70
- - stomp_message_send.rb
71
- extensions: []
72
-
73
85
  requirements: []
74
-
75
- dependencies: []
76
-
86
+ rubyforge_project: stompmessage
87
+ autorequire:
@@ -1,100 +0,0 @@
1
- require 'rubygems'
2
- require 'timeout'
3
- gem 'openwferu'
4
- require 'openwfe/participants/participants'
5
-
6
-
7
- module OpenWFE
8
-
9
- #
10
- # Participant to send/receive work items to stomp message servers applications
11
- # send message and asynch wait for response
12
- #
13
- # Timeoout may need to be changed
14
- #
15
- # On the return side, you can override the method handle_call_result
16
- # for better mappings between messages calls and the workitems.
17
- #
18
- class StompParticipant
19
- include LocalParticipant
20
- attr_accessor :timeout_val, :options, :msg_sender
21
- def initialize(topic, host='localhost', port=61613, timeout=4, &block)
22
-
23
-
24
- self.options={}
25
- self.options[:host]=host
26
- self.options[:port]=port
27
- self.options[:topic]=topic
28
- self.timeout_val = timeout
29
- self.msg_sender=StompMessage::StompSendTopic.new(self.options)
30
- self.msg_sender.setup_auto_close
31
- end
32
-
33
- #
34
- # The method called by the engine when the flow reaches an instance
35
- # of this Participant class.
36
- #
37
- def consume (workitem)
38
-
39
- m=prepare_call_params(workitem)
40
- puts "message is: #{m.to_xml}"
41
- # billing_sender.send_topic(m.body, arg_hash[:msisdn])
42
- # m=StompMessage::Message.new('stomp_BILLING', msg)
43
- header={}
44
- # header[:msisdn]=workitem.attributes[:msisdn]
45
- begin
46
- Timeout::timeout(self.timeout_val) {
47
- self.msg_sender.send_topic_acknowledge(m,header) {
48
- |msg| workitem=handle_call_result(msg, workitem)
49
- }
50
- }
51
- rescue Timeout::Error
52
- puts "STOMP participant:: consume(wi) exception"
53
- workitem.attributes["__result__"]=false
54
- workitem.attributes["stomp_TIMEOUT"]=true
55
- # raise "timeout"
56
- ensure
57
- reply_to_engine(workitem)
58
- end
59
-
60
-
61
-
62
- end
63
-
64
- #
65
- # The base implementation :prepares the message
66
- # param there is a workitem field with the same name.
67
- #
68
- # Feel free to override this method.
69
- #
70
- def prepare_call_params (workitem)
71
- m=StompMessage::Message.new(workitem.attributes[:command].to_s,
72
- workitem.attributes[:body].to_s)
73
- m
74
- # puts "message is: #{m.to_xml}"
75
- end
76
-
77
- #
78
- # This implementation simply stuffs the result into the workitem
79
- # as an attribute named "__result__".
80
- #
81
- # Feel free to override this method.
82
- #
83
- def handle_call_result (result, workitem)
84
-
85
- puts 'in handle action block'
86
- puts 'MESSAGE RECEIVED ----'
87
- m= StompMessage::Message.load_xml(result)
88
- workitem.attributes["__result__"]=m.to_xml
89
- workitem.attributes["command"]=m.command.to_s
90
- workitem.attributes["body"]=m.body.to_s
91
- puts "wi #{workitem.attributes.to_s}"
92
- workitem
93
-
94
- end
95
-
96
-
97
-
98
- end
99
-
100
- end