estorm-message-processor 0.1.6 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- OWQ1NzMyOWVlMzEzZmFmZDE4NjIzODlhMjFhMjUyOTk0Yzg2ZWU2Zg==
5
- data.tar.gz: !binary |-
6
- MTIzYjcyZjFmOWMyMGQzZjAzNzJmODRmYjg3ZDE3ZGJiYjkzYWFmZQ==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MDcwMjYxMDRkMDg1MWQ0MDYzODUyZmJlNmU0N2U5OTFhYmM3Yzc0ZGJhMTc5
10
- NzU3YzU1ZTFhMThmM2IzYmUyNTJlMGQ2YWEyOWFmZDVlZDI4ZGZmOTI0YmM0
11
- NzEyN2NhNjc5MWY2MmQxYWMwZDNmYzA2ZWQ4MGRkNmU4ODYzZTI=
12
- data.tar.gz: !binary |-
13
- MDExOGQwZDE1YTc0ODgzZmM0ZjYwY2E5Mjk3ODUxM2RmNGQyMThmYjg0Njc1
14
- YmIyMzEzNDI2Y2ZlMTgzODNhMWVlMDg4Mzg4MzM1ZGYwMzM2ZmY3ZTZkMGRk
15
- MzE3MGFkZTYyMDc0NzkwMzFhYjY3MDQ3OTI3YjI2YWEyZmY1Y2U=
2
+ SHA1:
3
+ metadata.gz: 2b81f8b2169e098058d7854e7aa8c485575d545f
4
+ data.tar.gz: 1503e3b04071f9874f3412d6a5d40e4ee3c41245
5
+ SHA512:
6
+ metadata.gz: d799962de1b19fca425f5e875339ea1c8de9fba92d3f012a42c92ba07113e38b8cc78595bc4cc262349ea654ffbe74f222bf910abb1aa8c885352d09bc35781c
7
+ data.tar.gz: a8160bd65e5e878a7b2df3f04eba6f85e97bab2e7618bf6d9f23d482ce2765b3944c97d29e8722c35a99e30890c943f908b449d8651c19c2fdb5fa104e5ca14c
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- estorm-message-processor (0.1.6)
4
+ estorm-message-processor (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -6,17 +6,17 @@ estorm-message-processor gem
6
6
  ============
7
7
 
8
8
 
9
- Simple gem to use in rails apps for AMQP inclusiong. Send a hash via AMQP and then have the message processor process the files. See the test pages
9
+ Simple gem to use in rails apps for AMQP inclusion. Send a hash via AMQP and then have the message processor process the files. See the test pages
10
10
 
11
11
  Usage
12
12
  =======
13
13
 
14
- pull in the normal files for ruby. Everytime a message is received with 'command' => "sendtemplates" delegate to that callback So add more delegate_routings and you will be able to handle multiple commands
14
+ pull in the normal files for ruby. Everytime a message is received with 'command' => "sendtemplates" delegated to that callback So add more delegate_routings and you will be able to handle multiple commands
15
15
 
16
16
  ## Setup delegate processor
17
- This is the callback processor
17
+ This is the callback processor in the consumer. Just define this in your script with the name of procedure like delegate_XXXXX
18
18
 
19
- class EstormMessageProcessor::Base
19
+ class EstormMessageProcessor::Consumer
20
20
  def delegate_sendtemplates(cmdhash)
21
21
  p=Promotion.find(cmdhash['promotion'].to_i)
22
22
  data=YAML.load(p.data)
@@ -27,18 +27,18 @@ This is the callback processor
27
27
 
28
28
  # Start the Message Processor
29
29
  begin
30
- config={:url => AMQPURL,:connecturlflag=> Rails.env.production? ,:queuename => CONTACT_MESSAGE, :blocking => true}
30
+ config={:url => AMQPURL,:connecturlflag=> Rails.env.production? ,:queuename => CONTACT_MESSAGE, :blocking => true, :timeout => 0, :consumer_name => "test consumer"}
31
31
  #puts "Starting SMS Gateway. Please check the log at #{LOGFILE}"
32
32
  EstormMessageProcessor::Base.logger=Logger.new(STDOUT)
33
33
  puts "Starting Bunny Contact Processor on #{config.inspect} "
34
34
  mp = EstormMessageProcessor::Base.new
35
- mp.start(config)
35
+ mp.start(config) # THIS MAY NEED TO BE IN a THREAD
36
36
  rescue Exception => ex
37
37
  puts "Exception in Message Processor: #{ex} at #{ex.backtrace.join("\n")}"
38
38
  end
39
39
 
40
40
  # send a message using the client
41
- Use the client to send a message to the delegate processor (background task)
41
+ Use the client to send a message to the delegate processor (background task). Note the command set to the callback processor above. You can also see multiple sends in the test files.
42
42
 
43
43
  def bunny_send
44
44
  cmdhash={'command'=>'sendtemplates', 'promotion'=>self.id.to_s}
@@ -47,6 +47,6 @@ Use the client to send a message to the delegate processor (background task)
47
47
  bunny.bunny_send(AMQPURL,Rails.env.production?,CONTACT_MESSAGE,cmdhash)
48
48
  end
49
49
 
50
- # config[:exit_when_empty] = true if you want to just process the messages in the queue
50
+ # set the config[:timeout] value if you want the task to exit. (eg supposedly this is how long until no message is received for the consumer to exist the processing loop)
51
51
  This is useful if you have a back ground task that you want to run occasionally and just process the messages and exit. For example on heroku you can schedule a job to run every hour and it will process the messages and exit. This will keep the costs down for the background task on heroku. (Of course you need to ensure that the job time is shorter than the heroku scheduler time)
52
52
 
@@ -4,7 +4,7 @@ require 'yaml'
4
4
 
5
5
  module EstormMessageProcessor
6
6
  class Base
7
- attr_reader :queue, :channel, :consumer
7
+ attr_reader :queue, :channel, :consumer, :conn
8
8
  # MT id counter.
9
9
  @@mt_id = 0
10
10
  def Base.logger
@@ -36,25 +36,34 @@ module EstormMessageProcessor
36
36
  end
37
37
 
38
38
  def tear_down_bunny
39
- if @conn!=nil && @conn.open?
39
+ if @conn!=nil && @conn.open? && @channel!=nil && @channel.open?
40
+ sleep 1
40
41
  @consumer.cancel if @consumer!=nil && !@consumer.cancelled?
41
- sleep 0.5
42
- @conn.close if @channel != nil && @channel.open?
42
+ sleep 1
43
+ # @queue.unsubscribe
44
+ # @conn.close if @channel != nil && @channel.open?
45
+ # sleep 0.5
43
46
  end
44
47
  msg= "closing bunny"
45
48
  logger.info msg
46
49
  end
50
+
47
51
  def queue_mgmt(config)
48
52
  msg= "[*] Waiting for messages in #{@queue.name}. blocking is #{config[:blocking]}"
49
53
  logger.info msg
50
54
  count=0
55
+ # @channel.prefetch(1) # set quality of service to only delivery one message at a time....
56
+ msg_count,consumer_count = @consumer.queue_statistics # just to get the stats before entering hte queue
51
57
  # @queue.subscribe(:block => config[:blocking]) do |delivery_info, properties, body|
52
58
  @consumer.on_delivery() do |delivery_info, metadata, payload|
53
59
  @consumer.process_messages(delivery_info,metadata,payload)
60
+ # @consumer.channel.acknowledge(delivery_info.delivery_tag, false) if @consumer.channel!=nil && @consumer.channel.open?
54
61
  msg= "ON DELIVERY: #{@consumer.count}: messages processed"
55
62
  logger.info msg
56
- msg_count,consumer_count = @consumer.queue_statistics
57
- @consumer.cancel if msg_count==0 and config[:exit_when_empty]
63
+
64
+ # ack the message to get the next message
65
+ #msg_count,consumer_count = @consumer.queue_statistics # POSSIBLE RACE CONDITION
66
+ # @consumer.cancel if msg_count==0 && config[:exit_when_empty]
58
67
  end
59
68
  end
60
69
 
@@ -62,21 +71,24 @@ module EstormMessageProcessor
62
71
  def start(config)
63
72
  msg= "Connecting to bunny environment #{config.inspect}"
64
73
  logger.info msg
65
- config[:exit_when_empty]=false if config[:exit_when_empty]==nil
66
74
  setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename])
67
- @consumer=EstormMessageProcessor::Consumer.new(@channel, @queue, config[:consumer_name], true, false, config)
75
+ #@consumer=EstormMessageProcessor::Consumer.new(@channel, @queue, config[:consumer_name], true, false, config)
76
+ @consumer=EstormMessageProcessor::Consumer.new(@channel, @queue)
77
+
68
78
  @consumer.logger=logger
69
79
  raise "consumer creation problem" if @consumer==nil
70
80
  msg_count,consumer_count =@consumer.queue_statistics
71
81
  queue_mgmt(config)
72
- @queue.subscribe_with(@consumer, :block => config[:blocking])
73
-
74
- loop do
82
+ # the block flag shuts down the thread. the timeout values says whether to unsubscriber
83
+ #need to set ack to true to manage the qos parameter
84
+ # retval= @queue.subscribe_with(@consumer,:ack => true, :block => config[:blocking], :timeout => config[:timeout])
85
+ # retval= @queue.subscribe_with(@consumer,:ack => true, :block => config[:blocking])
86
+ retval= @queue.subscribe_with(@consumer, :block => config[:blocking])
87
+ # loop do
75
88
  #should loop forever if blocking... otherwise needs a loop
76
- sleep 2
77
- break if @consumer.cancelled?
78
- end
79
- msg= "Ending======about to tear_down_bunny...."
89
+ # sleep 1
90
+ # end
91
+ msg= "Ending======about to tear_down_bunny [retval: #{retval}]...."
80
92
  logger.info msg
81
93
  tear_down_bunny
82
94
 
@@ -27,8 +27,9 @@ module EstormMessageProcessor
27
27
  def connection
28
28
  @conn
29
29
  end
30
- def bunny_send_no_close(url,flag,queuename,cmdhash)
31
- @conn,@channel=setup_bunny(url,flag)
30
+ #def bunny_send_no_close(url,flag,queuename,cmdhash)
31
+ def bunny_send_no_close(queuename,cmdhash)
32
+ # @conn,@channel=setup_bunny(url,flag)
32
33
  @queue = @channel.queue(queuename)
33
34
  #cmdhash={'command'=>'sendtemplates', 'promotion'=>self.id.to_s}
34
35
  @channel.default_exchange.publish(cmdhash.to_yaml, :routing_key => @queue.name)
@@ -14,7 +14,7 @@
14
14
  <img src="./assets/0.7.1/loading.gif" alt="loading"/>
15
15
  </div>
16
16
  <div id="wrapper" style="display:none;">
17
- <div class="timestamp">Generated <abbr class="timeago" title="2013-10-16T10:53:32+08:00">2013-10-16T10:53:32+08:00</abbr></div>
17
+ <div class="timestamp">Generated <abbr class="timeago" title="2013-10-17T08:53:34+08:00">2013-10-17T08:53:34+08:00</abbr></div>
18
18
  <ul class="group_tabs"></ul>
19
19
 
20
20
  <div id="content">
@@ -27,8 +27,9 @@ class EstormConsumerProcessTest < Minitest::Test
27
27
  end
28
28
  def test_cancel
29
29
  puts "testing consumer"
30
- config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testconsumerqueue', :blocking => true, :consumer_name => "test consumer"}
30
+ config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testconsumerqueue', :blocking => true, :timeout => 0, :consumer_name => "test consumer"}
31
31
  @f.setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename])
32
+ assert @f.channel.open? , "channel should be open"
32
33
  @consumer = EstormMessageProcessor::Consumer.new(@f.channel, @f.queue)
33
34
  @consumer.logger=@f.logger
34
35
  assert !@consumer.cancelled?, "should not be cancelled"
@@ -39,7 +40,7 @@ class EstormConsumerProcessTest < Minitest::Test
39
40
  end
40
41
  def test_consumer_increment
41
42
  puts "testing consumer"
42
- config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testconsumerqueue', :blocking => true, :consumer_name => "test consumer"}
43
+ config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testconsumerqueue',:timeout => 0, :blocking => true, :consumer_name => "test consumer"}
43
44
  @f.setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename])
44
45
  @consumer = EstormMessageProcessor::Consumer.new(@f.channel, @f.queue)
45
46
  @consumer.logger=@f.logger
@@ -49,9 +50,17 @@ class EstormConsumerProcessTest < Minitest::Test
49
50
  assert @consumer.increment
50
51
  assert @consumer.count==2, "should be 2 but is #{@consumer.count}"
51
52
  end
53
+ def test_qos
54
+ puts "test startup"
55
+ config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testdelegatequeue', :timeout => 0,:blocking => true,:consumer_name => "test consumer delete startup consumer"}
56
+ cmdhash={'command'=>'testdelegate', 'temp'=>'test_delegate'}
57
+ @f.setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename])
58
+ res=@f.channel.prefetch(1)
59
+ assert res.is_a?(AMQ::Protocol::Basic::QosOk), "should set prefetch #{res} methods "
60
+ end
52
61
  def test_delegate
53
62
  puts "test startup"
54
- config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testdelegatequeue', :blocking => true,:consumer_name => "test consumer delete startup consumer"}
63
+ config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testdelegatequeue', :timeout => 0,:blocking => true,:consumer_name => "test consumer delete startup consumer"}
55
64
  cmdhash={'command'=>'testdelegate', 'temp'=>'test_delegate'}
56
65
  @f.setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename])
57
66
  @consumer = EstormMessageProcessor::Consumer.new(@f.channel, @f.queue)
@@ -63,7 +72,7 @@ class EstormConsumerProcessTest < Minitest::Test
63
72
  end
64
73
  def test_consumer
65
74
  puts "testing consumer"
66
- config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testconsumerqueue2', :blocking => true, :consumer_name => "test consumer"}
75
+ config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testconsumerqueue2', :timeout => 0, :blocking => true, :consumer_name => "test consumer"}
67
76
  @f.setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename])
68
77
  @consumer = EstormMessageProcessor::Consumer.new(@f.channel, @f.queue)
69
78
  @consumer.logger=@f.logger
@@ -84,7 +93,7 @@ class EstormConsumerProcessTest < Minitest::Test
84
93
  end
85
94
  def test_queueu_stats
86
95
  puts "testing consumer"
87
- config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testconsumerqueue', :blocking => true, :consumer_name => "test consumer2"}
96
+ config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testconsumerqueue', :timeout => 0,:blocking => true, :consumer_name => "test consumer2"}
88
97
  @f.setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename])
89
98
  @consumer = EstormMessageProcessor::Consumer.new(@f.channel, @f.queue)
90
99
  @consumer.logger=@f.logger
@@ -62,7 +62,7 @@ class EstormMessageProcessTest < Minitest::Test
62
62
 
63
63
  def test_delegate
64
64
  puts "test delegate"
65
- config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testdelegatequeue', :blocking => true,:consumer_name => "test consumer delete startup consumer"}
65
+ config={:url => 'fakeurl',:connecturlflag=> false,:timeout => 0,:queuename => 'testdelegatequeue', :blocking => true,:consumer_name => "test consumer delete startup consumer"}
66
66
  cmdhash={'command'=>'testdelegate', 'temp'=>'test_delegate'}
67
67
  t1 =Thread.new {
68
68
  @f.start(config) }
@@ -70,26 +70,29 @@ class EstormMessageProcessTest < Minitest::Test
70
70
  assert @f.consumer!=nil, "consumer should not be nil"
71
71
  @f.consumer.send("delegate_testdelegate",cmdhash)
72
72
  assert MessageFlag.flag==true, "should receive message and set temp #{MessageFlag.flag}"
73
+ sleep 3
73
74
  end
74
75
  def test_basic_startup
75
76
  puts "test basic startup"
76
- config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testbasicqueue', :blocking => false,:consumer_name => "test basic non blocking consumer"}
77
+ config={:url => 'fakeurl',:connecturlflag=> false,:timeout => 0,:queuename => 'testbasicqueue', :blocking => false,:consumer_name => "test basic non blocking consumer"}
77
78
 
78
79
  t1 =Thread.new {
79
80
  @f.start(config) }
80
81
  sleep 2
81
- @f.tear_down_bunny #NEED TO FIGURE OUT HOW TO STOP
82
+ # @f.tear_down_bunny #NEED TO FIGURE OUT HOW TO STOP
82
83
  assert true,"should get here test_startup"
83
84
  end
84
85
  def test_startup
85
86
  puts "test startup"
86
- config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testqueue', :blocking => true,:consumer_name => "test startup consumer"}
87
+ config={:url => 'fakeurl',:connecturlflag=> false,:timeout => 0,:queuename => 'testqueue', :blocking => true,:consumer_name => "test startup consumer"}
87
88
  t1 =Thread.new {
88
89
  @f.start(config) }
89
90
  sleep 2
90
91
  @f.tear_down_bunny
92
+ sleep 1
91
93
  t1.exit
92
94
  assert true,"should get here test_startup"
95
+ sleep 3
93
96
  end
94
97
  def test_1yaml
95
98
  puts "in yaml test"
@@ -102,11 +105,11 @@ class EstormMessageProcessTest < Minitest::Test
102
105
  def test_message
103
106
  puts "test message"
104
107
  assert MessageFlag.flag==false, "should be flase #{MessageFlag.inspect}"
105
- config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testseveralMessages', :blocking => true, :consumer_name => "test message consumer"}
108
+ config={:url => 'fakeurl',:connecturlflag=> false,:timeout => 0,:queuename => 'testsevalMessages', :blocking => true, :consumer_name => "test message consumer"}
106
109
  t1=Thread.new {
107
110
  @f.start(config)
108
111
  puts " should not get here this thread about to exit in tes_messag"}
109
- sleep 6
112
+ sleep 1
110
113
  t2= Thread.new {
111
114
 
112
115
  cmdhash={'command'=>'testdelegate', 'temp'=>'temp'}
@@ -116,22 +119,23 @@ class EstormMessageProcessTest < Minitest::Test
116
119
  puts "after bunny send test_message"
117
120
  }
118
121
  puts "after client in test message"
119
- sleep 1
122
+ sleep 5
123
+
120
124
  assert MessageFlag.flag==true, "should receive message and set temp #{MessageFlag.flag}"
121
125
 
122
- @f.tear_down_bunny
126
+ sleep 1
123
127
  t1.exit
124
128
  t2.exit
125
-
129
+ sleep 1
126
130
  end
127
131
  def test_several_message
128
132
  puts "test several message"
129
133
  assert MessageFlag.flag==false, "should be flase #{MessageFlag.inspect}"
130
- config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testqueueMessage', :blocking => true, :consumer_name => "test message consumer"}
134
+ config={:url => 'fakeurl',:connecturlflag=> false,:timeout => 0,:queuename => 'testqueuesMessage', :blocking => true, :consumer_name => "test message consumer"}
131
135
  t1=Thread.new {
132
136
  @f.start(config)
133
137
  puts " should not get here this thread about to exit in tes_messag"}
134
- sleep 2
138
+ sleep 1
135
139
  t2= Thread.new {
136
140
 
137
141
  cmdhash={'command'=>'testdelegate2', 'temp'=>'serveral messages'}
@@ -144,26 +148,71 @@ class EstormMessageProcessTest < Minitest::Test
144
148
  }
145
149
  }
146
150
  puts "after client in test message"
147
- sleep 1
148
- @f.tear_down_bunny
151
+ sleep 15
152
+ # @f.tear_down_bunny
153
+ sleep 1
149
154
  assert MessageFlag.testval==7, "should receive 7 message and set temp #{MessageFlag.testval}"
150
155
 
151
156
 
152
157
  t1.exit
153
158
  t2.exit
154
-
159
+ sleep 3
155
160
  end
161
+ def test_several_message_again
162
+ puts "test several message"
163
+ assert MessageFlag.flag==false, "should be flase #{MessageFlag.inspect}"
164
+ config={:url => 'fakeurl',:connecturlflag=> false,:timeout => 0,:queuename => 'testqueuesMessage again', :blocking => true, :consumer_name => "test message consumer"}
165
+ t1=Thread.new {
166
+ @f.start(config)
167
+ puts " should not get here this thread about to exit in tes_messag"}
168
+ sleep 1
169
+ t2= Thread.new {
170
+
171
+ cmdhash={'command'=>'testdelegate2', 'temp'=>'serveral messages'}
172
+ puts "----> to system [x] sending #{cmdhash.inspect}"
173
+ 1.upto(7) { |i|
174
+ bunnysender=EstormMessageProcessor::Client.new
175
+ cmdhash['temp']="mesage #{i}"
176
+ bunnysender.bunny_send(config[:url],config[:connnecturlflag],config[:queuename],cmdhash)
177
+ puts "after bunny send test_message"
178
+ }
179
+ }
180
+ puts "after client in test message"
181
+ sleep 15
182
+ # @f.tear_down_bunny
183
+ sleep 1
184
+ assert MessageFlag.testval==7, "should receive 7 message and set temp #{MessageFlag.testval}"
185
+ count=4
186
+ t2= Thread.new {
187
+
188
+ cmdhash={'command'=>'testdelegate2', 'temp'=>'serveral messages'}
189
+ puts "----> to system [x] sending #{cmdhash.inspect}"
190
+ 1.upto(count) { |i|
191
+ bunnysender=EstormMessageProcessor::Client.new
192
+ cmdhash['temp']="mesage #{i}"
193
+ bunnysender.bunny_send(config[:url],config[:connnecturlflag],config[:queuename],cmdhash)
194
+ puts "after bunny send test_message"
195
+ }
196
+ }
197
+ sleep 10
198
+ assert MessageFlag.testval==7+count, "should receive #{7+count} message and set temp #{MessageFlag.testval}"
199
+ t1.exit
200
+ t2.exit
201
+ sleep 3
202
+ end
156
203
  def test_client
157
204
  puts "test client -- basic"
158
205
  cmdhash={'command'=>'testdelegate2', 'promotion'=>2.to_s}
159
206
  puts "----> to system [x] sending #{cmdhash.inspect}"
160
- config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testqueue7', :blocking => true, :consumer_name => "test consumer"}
207
+ config={:url => 'fakeurl',:connecturlflag=> false,:timeout => 0,:queuename => 'testqueue7', :blocking => true, :consumer_name => "test consumer"}
161
208
  bunny=EstormMessageProcessor::Client.new
162
209
  assert bunny!=nil, "bunny should not be nil"
163
- bunny.bunny_send_no_close(config[:url],config[:connnecturlflag],config[:queuename],cmdhash)
210
+ bunny.setup_bunny(config[:url],config[:connnecturlflag])
211
+ bunny.bunny_send_no_close(config[:queuename],cmdhash)
164
212
  assert bunny.connection!=nil, "should be ok"
165
213
  res=bunny.connection.close
166
214
  assert res=='closed'.to_sym, "should be closed: #{res.inspect}"
215
+ sleep 3
167
216
  end
168
217
 
169
218
 
@@ -0,0 +1,89 @@
1
+ puts File.dirname(__FILE__)
2
+ require 'yaml'
3
+ require File.dirname(__FILE__) + '/test_helper.rb'
4
+ class MessageFlag
5
+
6
+ def self.reset
7
+ puts "reset called"
8
+ @@flag=false
9
+ @@test=0
10
+ end
11
+ def self.setflag
12
+ puts "set flag called"
13
+ @@flag=true
14
+ end
15
+ def self.flag
16
+
17
+ @@flag
18
+ end
19
+ def self.testval
20
+ @@test
21
+ end
22
+ def self.increment
23
+ puts "increment called"
24
+ @@test=MessageFlag.testval+1
25
+ end
26
+ end
27
+ class EstormMessageProcessor::Consumer
28
+
29
+ def delegate_testdelegate3(cmdhash)
30
+ msg= "DELEGATE CALLED: test delegate 3 received #{cmdhash.inspect}"
31
+ logger.info msg
32
+ puts msg
33
+ MessageFlag.increment
34
+ end
35
+ end
36
+
37
+ class EstormMessageProcessTest < Minitest::Test
38
+
39
+ def setup
40
+ EstormMessageProcessor::Base.logger=Logger.new(STDERR)
41
+ @f=EstormMessageProcessor::Base.new
42
+ @@temp=false
43
+ MessageFlag.reset
44
+ puts "after setup"
45
+ end
46
+
47
+ def test_basic
48
+ assert @f!=nil, "should be valid"
49
+ assert !@@temp, "should be false"
50
+ assert !MessageFlag.flag, "should be false"
51
+ MessageFlag.setflag
52
+ assert MessageFlag.flag, "should be true"
53
+ assert MessageFlag.testval==0, "should be 0"
54
+ MessageFlag.increment
55
+ assert MessageFlag.flag, "should be false"
56
+ end
57
+ def test_processor_exits_after_queue_empty
58
+ puts "test several message"
59
+ assert MessageFlag.flag==false, "should be flase #{MessageFlag.inspect}"
60
+ config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testqueueMessageExit', :blocking => true, :consumer_name => "test exit consumer", :timeout => 10 }
61
+ # PRELOAD THE QUEUE WITH MESSAGES
62
+ bunnysender=EstormMessageProcessor::Client.new
63
+ bunnysender.setup_bunny(config[:url],config[:connnecturlflag])
64
+
65
+ cmdhash={'command'=>'testdelegate3', 'temp'=>'serveral messages'}
66
+ puts "----> to system [x] sending #{cmdhash.inspect}"
67
+
68
+ 1.upto(7) { |i|
69
+
70
+ cmdhash['temp']="mesage #{i}"
71
+ bunnysender.bunny_send_no_close(config[:queuename],cmdhash)
72
+ puts "after bunny send test_message: #{cmdhash['temp']}"
73
+ }
74
+
75
+ puts "after client in test message"
76
+ @f.start(config)
77
+ # bunnysender.connection.close
78
+ puts " should get here this thread about to exit in tes_messag"
79
+
80
+ time=30
81
+ puts "sleeping #{time} seconds"
82
+ sleep time
83
+
84
+ sleep 1
85
+
86
+ assert MessageFlag.testval==7, "should receive 7 message and set temp #{MessageFlag.testval}"
87
+
88
+ end
89
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: estorm-message-processor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Sproule
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-16 00:00:00.000000000 Z
11
+ date: 2013-10-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: a gem to help rails app process AMQP queues for background jobs
14
14
  email: scott.sproule@ficonab.com
@@ -64,6 +64,7 @@ files:
64
64
  - test/test_consumer.rb
65
65
  - test/test_estorm.rb
66
66
  - test/test_helper.rb
67
+ - test/test_single.rb
67
68
  - Gemfile
68
69
  - Gemfile.lock
69
70
  - README.md
@@ -77,12 +78,12 @@ require_paths:
77
78
  - lib
78
79
  required_ruby_version: !ruby/object:Gem::Requirement
79
80
  requirements:
80
- - - ! '>='
81
+ - - '>='
81
82
  - !ruby/object:Gem::Version
82
83
  version: '0'
83
84
  required_rubygems_version: !ruby/object:Gem::Requirement
84
85
  requirements:
85
- - - ! '>='
86
+ - - '>='
86
87
  - !ruby/object:Gem::Version
87
88
  version: 1.3.4
88
89
  requirements: []