estorm-message-processor 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +14 -6
- data/Gemfile.lock +1 -1
- data/README.md +3 -0
- data/lib/estorm-message-processor/base.rb +46 -61
- data/lib/estorm-message-processor/client.rb +8 -8
- data/lib/estorm-message-processor/consumer.rb +58 -0
- data/test/coverage/index.html +1 -1
- data/test/test_consumer.rb +124 -0
- data/test/test_estorm.rb +124 -20
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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=
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -47,3 +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
|
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
|
+
|
@@ -3,8 +3,8 @@ require 'bunny'
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
5
|
module EstormMessageProcessor
|
6
|
-
class Base
|
7
|
-
|
6
|
+
class Base
|
7
|
+
attr_reader :queue, :channel, :consumer
|
8
8
|
# MT id counter.
|
9
9
|
@@mt_id = 0
|
10
10
|
def Base.logger
|
@@ -19,84 +19,69 @@ module EstormMessageProcessor
|
|
19
19
|
@@logger
|
20
20
|
end
|
21
21
|
|
22
|
-
|
23
|
-
begin
|
24
|
-
cmdhash=YAML.load(body)
|
25
|
-
delegatestring="delegate_#{cmdhash['command']}"
|
26
|
-
# create procedures named delegate_command accepting cmdhash
|
27
|
-
msg = "-----> [gem estorm message processor] Received from App #{body} calling delegate #{delegatestring} "
|
28
|
-
logger.info msg
|
29
|
-
self.send(delegatestring,cmdhash)
|
30
|
-
#load the promotion and process through data
|
31
|
-
|
32
|
-
rescue Exception => e # add could not convert integer
|
33
|
-
msg= "found bunny exception #{e.message} found #{e.inspect} #{e.backtrace}..." #THIS NEEDS WORK!
|
34
|
-
logger.info msg
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
22
|
+
|
38
23
|
|
39
24
|
def logger
|
40
25
|
EstormMessageProcessor::Base.logger
|
41
26
|
end
|
42
27
|
|
43
28
|
def setup_bunny_communications(url,flag,queuename)
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
@client.start
|
49
|
-
# msg= "client inspect #{@client.inspect}"
|
50
|
-
# logger.info msg
|
51
|
-
rescue Bunny::PossibleAuthenticationFailureError => e
|
52
|
-
puts "Could not authenticate "
|
53
|
-
msg= "logger could not authenticate #{e.message}"
|
54
|
-
logger.info msg
|
55
|
-
end
|
56
|
-
@channel = @client.create_channel
|
29
|
+
@client=EstormMessageProcessor::Client.new
|
30
|
+
@conn,@channel=@client.setup_bunny(url,flag)
|
31
|
+
raise "connection problem with #{@client.inspect}" if @conn==nil
|
32
|
+
@channel = @conn.create_channel
|
57
33
|
@queue = @channel.queue(queuename)
|
58
34
|
msg= "set up active MQ on #{queuename}"
|
59
35
|
logger.info msg
|
60
36
|
end
|
61
37
|
|
62
38
|
def tear_down_bunny
|
63
|
-
|
39
|
+
if @conn!=nil && @conn.open?
|
40
|
+
@consumer.cancel if @consumer!=nil && !@consumer.cancelled?
|
41
|
+
sleep 0.5
|
42
|
+
@conn.close if @channel != nil && @channel.open?
|
43
|
+
end
|
64
44
|
msg= "closing bunny"
|
65
45
|
logger.info msg
|
66
46
|
end
|
67
|
-
|
47
|
+
def queue_mgmt(config)
|
48
|
+
msg= "[*] Waiting for messages in #{@queue.name}. blocking is #{config[:blocking]}"
|
49
|
+
logger.info msg
|
50
|
+
count=0
|
51
|
+
# @queue.subscribe(:block => config[:blocking]) do |delivery_info, properties, body|
|
52
|
+
@consumer.on_delivery() do |delivery_info, metadata, payload|
|
53
|
+
@consumer.process_messages(delivery_info,metadata,payload)
|
54
|
+
msg= "ON DELIVERY: #{@consumer.count}: messages processed"
|
55
|
+
logger.info msg
|
56
|
+
msg_count,consumer_count = @consumer.queue_statistics
|
57
|
+
@consumer.cancel if msg_count==0 and config[:exit_when_empty]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
|
68
62
|
def start(config)
|
63
|
+
msg= "Connecting to bunny environment #{config.inspect}"
|
64
|
+
logger.info msg
|
65
|
+
config[:exit_when_empty]=false if config[:exit_when_empty]==nil
|
69
66
|
setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename])
|
70
|
-
|
71
|
-
|
67
|
+
@consumer=EstormMessageProcessor::Consumer.new(@channel, @queue, config[:consumer_name], true, false, config)
|
68
|
+
@consumer.logger=logger
|
69
|
+
raise "consumer creation problem" if @consumer==nil
|
70
|
+
msg_count,consumer_count =@consumer.queue_statistics
|
71
|
+
queue_mgmt(config)
|
72
|
+
@queue.subscribe_with(@consumer, :block => config[:blocking])
|
73
|
+
|
74
|
+
loop do
|
75
|
+
#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...."
|
72
80
|
logger.info msg
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
msg= "[*] Waiting for messages in #{@queue.name}. blocking is #{config[:blocking]}"
|
77
|
-
logger.info msg
|
78
|
-
msg_count =@queue.message_count
|
79
|
-
consumer_count =@queue.consumer_count
|
80
|
-
msg = "queue status for queue #{config[:queuename]} message count: #{msg_count} consumers: #{consumer_count}"
|
81
|
-
logger.info msg
|
82
|
-
@queue.subscribe(:block => config[:blocking]) do |delivery_info, properties, body|
|
83
|
-
process_messages(delivery_info,properties,body)
|
84
|
-
# cancel the consumer to exit
|
85
|
-
#delivery_info.consumer.cancel
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
89
|
-
msg= "Disconnected. Reconnecting in 5 seconds.."
|
90
|
-
logger.info msg
|
91
|
-
#puts msg
|
92
|
-
tear_down_bunny
|
93
|
-
sleep 1
|
94
|
-
setup_bunny_communications
|
95
|
-
sleep 4
|
96
|
-
|
97
|
-
|
81
|
+
tear_down_bunny
|
82
|
+
|
98
83
|
end
|
99
|
-
|
84
|
+
|
100
85
|
|
101
86
|
|
102
87
|
|
@@ -13,25 +13,25 @@ module EstormMessageProcessor
|
|
13
13
|
rescue Bunny::PossibleAuthenticationFailureError => e
|
14
14
|
puts "Could not authenticate as #{conn.username}"
|
15
15
|
end
|
16
|
-
channel = @conn.create_channel
|
16
|
+
@channel = @conn.create_channel
|
17
17
|
#puts "connected: #{conn.inspect}"
|
18
|
-
[@conn
|
18
|
+
[@conn,@channel]
|
19
19
|
end
|
20
20
|
def bunny_send(url,flag,queuename,cmdhash)
|
21
|
-
@conn
|
22
|
-
queue = channel.queue(queuename)
|
21
|
+
@conn,@channel=setup_bunny(url,flag)
|
22
|
+
@queue = @channel.queue(queuename)
|
23
23
|
#cmdhash={'command'=>'sendtemplates', 'promotion'=>self.id.to_s}
|
24
|
-
channel.default_exchange.publish(cmdhash.to_yaml, :routing_key => queue.name)
|
24
|
+
@channel.default_exchange.publish(cmdhash.to_yaml, :routing_key => @queue.name)
|
25
25
|
@conn.close
|
26
26
|
end
|
27
27
|
def connection
|
28
28
|
@conn
|
29
29
|
end
|
30
30
|
def bunny_send_no_close(url,flag,queuename,cmdhash)
|
31
|
-
@conn
|
32
|
-
queue = channel.queue(queuename)
|
31
|
+
@conn,@channel=setup_bunny(url,flag)
|
32
|
+
@queue = @channel.queue(queuename)
|
33
33
|
#cmdhash={'command'=>'sendtemplates', 'promotion'=>self.id.to_s}
|
34
|
-
channel.default_exchange.publish(cmdhash.to_yaml, :routing_key => queue.name)
|
34
|
+
@channel.default_exchange.publish(cmdhash.to_yaml, :routing_key => @queue.name)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bunny'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module EstormMessageProcessor
|
6
|
+
class Consumer < Bunny::Consumer
|
7
|
+
attr_accessor :logger
|
8
|
+
def cancelled?
|
9
|
+
@cancelled
|
10
|
+
end
|
11
|
+
def count
|
12
|
+
@mycount=0 if @mycount==nil
|
13
|
+
@mycount
|
14
|
+
end
|
15
|
+
def increment
|
16
|
+
@mycount=self.count+1
|
17
|
+
end
|
18
|
+
|
19
|
+
def handle_cancellation(_)
|
20
|
+
|
21
|
+
msg="consumer cancellation queue called"
|
22
|
+
@logger.info msg
|
23
|
+
@cancelled = true
|
24
|
+
end
|
25
|
+
# process message
|
26
|
+
def process_messages(delivery_info,metadata,body)
|
27
|
+
begin
|
28
|
+
cmdhash=YAML.load(body)
|
29
|
+
delegatestring="delegate_#{cmdhash['command']}"
|
30
|
+
# create procedures named delegate_command accepting cmdhash
|
31
|
+
msg = "-----> [gem estorm message processor: consumer] Received from App #{body} calling delegate #{delegatestring} count: #{self.count} "
|
32
|
+
@logger.info msg
|
33
|
+
self.send(delegatestring,cmdhash)
|
34
|
+
# self.send(delegatestring,cmdhash)
|
35
|
+
#load the promotion and process through data
|
36
|
+
self.increment
|
37
|
+
rescue Exception => e # add could not convert integer
|
38
|
+
msg= "[gem estorm message processor] bunny exception #{e.message} found #{e.inspect} #{e.backtrace}..." #THIS NEEDS WORK!
|
39
|
+
@logger.info msg
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
# get the queue statistics and log it.
|
44
|
+
def queue_statistics
|
45
|
+
msg_count=0
|
46
|
+
begin
|
47
|
+
msg_count =@queue.message_count
|
48
|
+
consumer_count =@queue.consumer_count
|
49
|
+
msg = "queue status for queue [#{@queue.name}] message count: #{msg_count} consumers: #{consumer_count}"
|
50
|
+
@logger.info msg if @logger!=nil
|
51
|
+
rescue Exception => e
|
52
|
+
msg = "exception in queue statistics #{e.inspect}"
|
53
|
+
@logger.info msg if @logger!=nil
|
54
|
+
end
|
55
|
+
[msg_count, consumer_count]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/test/coverage/index.html
CHANGED
@@ -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-
|
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>
|
18
18
|
<ul class="group_tabs"></ul>
|
19
19
|
|
20
20
|
<div id="content">
|
@@ -0,0 +1,124 @@
|
|
1
|
+
puts File.dirname(__FILE__)
|
2
|
+
require 'yaml'
|
3
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
4
|
+
class EstormMessageProcessor::Consumer
|
5
|
+
attr_reader :conflag
|
6
|
+
def delegate_testdelegate(cmdhash)
|
7
|
+
msg= "DELEGATE CALLED: test delegate received #{cmdhash.inspect}"
|
8
|
+
logger.info msg
|
9
|
+
puts msg
|
10
|
+
@conflag=true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class EstormConsumerProcessTest < Minitest::Test
|
15
|
+
|
16
|
+
def setup
|
17
|
+
EstormMessageProcessor::Base.logger=Logger.new(STDERR)
|
18
|
+
@f=EstormMessageProcessor::Base.new
|
19
|
+
@@temp=false
|
20
|
+
|
21
|
+
puts "after setup"
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_basic
|
25
|
+
assert @f!=nil, "should be valid"
|
26
|
+
assert !@@temp, "should be false"
|
27
|
+
end
|
28
|
+
def test_cancel
|
29
|
+
puts "testing consumer"
|
30
|
+
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testconsumerqueue', :blocking => true, :consumer_name => "test consumer"}
|
31
|
+
@f.setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename])
|
32
|
+
@consumer = EstormMessageProcessor::Consumer.new(@f.channel, @f.queue)
|
33
|
+
@consumer.logger=@f.logger
|
34
|
+
assert !@consumer.cancelled?, "should not be cancelled"
|
35
|
+
tag=@consumer.consumer_tag
|
36
|
+
ack=@consumer.cancel
|
37
|
+
puts "ack string is #{ack}"
|
38
|
+
assert ack.consumer_tag==tag, "should be cancelled #{ack} #{ack.consumer_tag} #{tag}"
|
39
|
+
end
|
40
|
+
def test_consumer_increment
|
41
|
+
puts "testing consumer"
|
42
|
+
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testconsumerqueue', :blocking => true, :consumer_name => "test consumer"}
|
43
|
+
@f.setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename])
|
44
|
+
@consumer = EstormMessageProcessor::Consumer.new(@f.channel, @f.queue)
|
45
|
+
@consumer.logger=@f.logger
|
46
|
+
assert @consumer.count!=nil, "should not be nil"
|
47
|
+
assert @consumer.count==0, "should be 0"
|
48
|
+
assert @consumer.increment==1, "should be 1 but is #{@consumer.count}"
|
49
|
+
assert @consumer.increment
|
50
|
+
assert @consumer.count==2, "should be 2 but is #{@consumer.count}"
|
51
|
+
end
|
52
|
+
def test_delegate
|
53
|
+
puts "test startup"
|
54
|
+
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testdelegatequeue', :blocking => true,:consumer_name => "test consumer delete startup consumer"}
|
55
|
+
cmdhash={'command'=>'testdelegate', 'temp'=>'test_delegate'}
|
56
|
+
@f.setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename])
|
57
|
+
@consumer = EstormMessageProcessor::Consumer.new(@f.channel, @f.queue)
|
58
|
+
@consumer.logger=@f.logger
|
59
|
+
assert !@consumer.cancelled?, "should not be cancelled"
|
60
|
+
@consumer.send("delegate_testdelegate",cmdhash)
|
61
|
+
sleep 1
|
62
|
+
assert @consumer.conflag==true, "should receive message and set temp #{@consumer.inspect}"
|
63
|
+
end
|
64
|
+
def test_consumer
|
65
|
+
puts "testing consumer"
|
66
|
+
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testconsumerqueue2', :blocking => true, :consumer_name => "test consumer"}
|
67
|
+
@f.setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename])
|
68
|
+
@consumer = EstormMessageProcessor::Consumer.new(@f.channel, @f.queue)
|
69
|
+
@consumer.logger=@f.logger
|
70
|
+
assert !@consumer.cancelled?, "should not be cancelled"
|
71
|
+
res=""
|
72
|
+
t=Thread.new {
|
73
|
+
@f.queue.subscribe_with(@consumer)
|
74
|
+
sleep 1
|
75
|
+
x = @f.channel.default_exchange
|
76
|
+
# Publish messages
|
77
|
+
x.publish('Hello', :routing_key =>config[:queuename])
|
78
|
+
res=@f.queue.delete
|
79
|
+
puts "res is #{res}"
|
80
|
+
}
|
81
|
+
sleep 3
|
82
|
+
assert @consumer.cancelled?, "should be cancelled #{res} "
|
83
|
+
t.exit
|
84
|
+
end
|
85
|
+
def test_queueu_stats
|
86
|
+
puts "testing consumer"
|
87
|
+
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testconsumerqueue', :blocking => true, :consumer_name => "test consumer2"}
|
88
|
+
@f.setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename])
|
89
|
+
@consumer = EstormMessageProcessor::Consumer.new(@f.channel, @f.queue)
|
90
|
+
@consumer.logger=@f.logger
|
91
|
+
assert @consumer.consumer_tag=config[:consumer_name]
|
92
|
+
mc,cc=@consumer.queue_statistics
|
93
|
+
assert mc!=nil, "mc should have vlue"
|
94
|
+
assert cc!=nil, "concsumer count should have value"
|
95
|
+
assert true, "should get here without a problem"
|
96
|
+
end
|
97
|
+
|
98
|
+
#def test_one_shotclient
|
99
|
+
# assert MessageFlag.flag==false, "should be flase #{MessageFlag.inspect}"
|
100
|
+
# config={:url => 'fakeurl',:exit_when_empty => true,:connecturlflag=> false,:queuename => 'testqueue', :blocking => true}
|
101
|
+
# Thread.new {
|
102
|
+
|
103
|
+
# cmdhash={'command'=>'testdelegate2', 'temp'=>'temp'}
|
104
|
+
# puts "----> to system [x] sending 5 messages #{cmdhash.inspect}"
|
105
|
+
# 1.upto(5) {|i| # send five messages
|
106
|
+
# bunny=EstormMessageProcessor::Client.new
|
107
|
+
# bunny.bunny_send(config[:url],config[:connnecturlflag],config[:queuename],cmdhash)
|
108
|
+
# puts "after bunny send" }
|
109
|
+
# }
|
110
|
+
# sleep 2
|
111
|
+
|
112
|
+
# @f.start(config)
|
113
|
+
# sleep 10
|
114
|
+
|
115
|
+
# assert MessageFlag.testval==5, "should receive 5 message and set #{MessageFlag.inspect}"
|
116
|
+
# @f.tear_down_bunny
|
117
|
+
|
118
|
+
#end
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
end
|
data/test/test_estorm.rb
CHANGED
@@ -2,20 +2,39 @@ puts File.dirname(__FILE__)
|
|
2
2
|
require 'yaml'
|
3
3
|
require File.dirname(__FILE__) + '/test_helper.rb'
|
4
4
|
class MessageFlag
|
5
|
-
|
5
|
+
|
6
|
+
def self.reset
|
7
|
+
puts "reset called"
|
8
|
+
@@flag=false
|
9
|
+
@@test=0
|
10
|
+
end
|
6
11
|
def self.setflag
|
12
|
+
puts "set flag called"
|
7
13
|
@@flag=true
|
8
14
|
end
|
9
15
|
def self.flag
|
16
|
+
|
10
17
|
@@flag
|
11
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
|
12
26
|
end
|
13
|
-
class EstormMessageProcessor::
|
27
|
+
class EstormMessageProcessor::Consumer
|
14
28
|
def delegate_testdelegate2(cmdhash)
|
15
|
-
|
29
|
+
msg= "DELEGATE CALLED: test delegate2 received #{cmdhash.inspect}"
|
30
|
+
logger.info msg
|
31
|
+
puts msg
|
32
|
+
MessageFlag.increment
|
16
33
|
end
|
17
34
|
def delegate_testdelegate(cmdhash)
|
18
|
-
|
35
|
+
msg= "DELEGATE CALLED: test delegate received #{cmdhash.inspect}"
|
36
|
+
logger.info msg
|
37
|
+
puts msg
|
19
38
|
MessageFlag.setflag
|
20
39
|
end
|
21
40
|
end
|
@@ -26,22 +45,51 @@ class EstormMessageProcessTest < Minitest::Test
|
|
26
45
|
EstormMessageProcessor::Base.logger=Logger.new(STDERR)
|
27
46
|
@f=EstormMessageProcessor::Base.new
|
28
47
|
@@temp=false
|
48
|
+
MessageFlag.reset
|
29
49
|
puts "after setup"
|
30
50
|
end
|
31
51
|
|
32
52
|
def test_basic
|
33
53
|
assert @f!=nil, "should be valid"
|
34
54
|
assert !@@temp, "should be false"
|
55
|
+
assert !MessageFlag.flag, "should be false"
|
56
|
+
MessageFlag.setflag
|
57
|
+
assert MessageFlag.flag, "should be true"
|
58
|
+
assert MessageFlag.testval==0, "should be 0"
|
59
|
+
MessageFlag.increment
|
60
|
+
assert MessageFlag.flag, "should be false"
|
35
61
|
end
|
36
62
|
|
63
|
+
def test_delegate
|
64
|
+
puts "test delegate"
|
65
|
+
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testdelegatequeue', :blocking => true,:consumer_name => "test consumer delete startup consumer"}
|
66
|
+
cmdhash={'command'=>'testdelegate', 'temp'=>'test_delegate'}
|
67
|
+
t1 =Thread.new {
|
68
|
+
@f.start(config) }
|
69
|
+
sleep 1
|
70
|
+
assert @f.consumer!=nil, "consumer should not be nil"
|
71
|
+
@f.consumer.send("delegate_testdelegate",cmdhash)
|
72
|
+
assert MessageFlag.flag==true, "should receive message and set temp #{MessageFlag.flag}"
|
73
|
+
end
|
74
|
+
def test_basic_startup
|
75
|
+
puts "test basic startup"
|
76
|
+
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testbasicqueue', :blocking => false,:consumer_name => "test basic non blocking consumer"}
|
77
|
+
|
78
|
+
t1 =Thread.new {
|
79
|
+
@f.start(config) }
|
80
|
+
sleep 2
|
81
|
+
@f.tear_down_bunny #NEED TO FIGURE OUT HOW TO STOP
|
82
|
+
assert true,"should get here test_startup"
|
83
|
+
end
|
37
84
|
def test_startup
|
38
85
|
puts "test startup"
|
39
|
-
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testqueue', :blocking => true}
|
40
|
-
Thread.new {
|
41
|
-
|
42
|
-
sleep
|
43
|
-
@f.tear_down_bunny
|
44
|
-
|
86
|
+
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testqueue', :blocking => true,:consumer_name => "test startup consumer"}
|
87
|
+
t1 =Thread.new {
|
88
|
+
@f.start(config) }
|
89
|
+
sleep 2
|
90
|
+
@f.tear_down_bunny
|
91
|
+
t1.exit
|
92
|
+
assert true,"should get here test_startup"
|
45
93
|
end
|
46
94
|
def test_1yaml
|
47
95
|
puts "in yaml test"
|
@@ -52,31 +100,64 @@ class EstormMessageProcessTest < Minitest::Test
|
|
52
100
|
assert loaded['test']==fred['test'],"values should be smae"
|
53
101
|
end
|
54
102
|
def test_message
|
55
|
-
puts "test
|
103
|
+
puts "test message"
|
56
104
|
assert MessageFlag.flag==false, "should be flase #{MessageFlag.inspect}"
|
57
|
-
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => '
|
58
|
-
Thread.new {
|
59
|
-
@f.start(config)
|
105
|
+
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testseveralMessages', :blocking => true, :consumer_name => "test message consumer"}
|
106
|
+
t1=Thread.new {
|
107
|
+
@f.start(config)
|
108
|
+
puts " should not get here this thread about to exit in tes_messag"}
|
60
109
|
sleep 6
|
61
|
-
|
62
|
-
Thread.new {
|
110
|
+
t2= Thread.new {
|
63
111
|
|
64
112
|
cmdhash={'command'=>'testdelegate', 'temp'=>'temp'}
|
65
113
|
puts "----> to system [x] sending #{cmdhash.inspect}"
|
66
114
|
bunny=EstormMessageProcessor::Client.new
|
67
115
|
bunny.bunny_send(config[:url],config[:connnecturlflag],config[:queuename],cmdhash)
|
68
|
-
puts "after bunny send"
|
116
|
+
puts "after bunny send test_message"
|
69
117
|
}
|
70
118
|
puts "after client in test message"
|
71
|
-
sleep
|
72
|
-
|
119
|
+
sleep 1
|
120
|
+
assert MessageFlag.flag==true, "should receive message and set temp #{MessageFlag.flag}"
|
121
|
+
|
73
122
|
@f.tear_down_bunny
|
123
|
+
t1.exit
|
124
|
+
t2.exit
|
74
125
|
|
75
126
|
end
|
127
|
+
def test_several_message
|
128
|
+
puts "test several message"
|
129
|
+
assert MessageFlag.flag==false, "should be flase #{MessageFlag.inspect}"
|
130
|
+
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testqueueMessage', :blocking => true, :consumer_name => "test message consumer"}
|
131
|
+
t1=Thread.new {
|
132
|
+
@f.start(config)
|
133
|
+
puts " should not get here this thread about to exit in tes_messag"}
|
134
|
+
sleep 2
|
135
|
+
t2= Thread.new {
|
136
|
+
|
137
|
+
cmdhash={'command'=>'testdelegate2', 'temp'=>'serveral messages'}
|
138
|
+
puts "----> to system [x] sending #{cmdhash.inspect}"
|
139
|
+
1.upto(7) { |i|
|
140
|
+
bunnysender=EstormMessageProcessor::Client.new
|
141
|
+
cmdhash['temp']="mesage #{i}"
|
142
|
+
bunnysender.bunny_send(config[:url],config[:connnecturlflag],config[:queuename],cmdhash)
|
143
|
+
puts "after bunny send test_message"
|
144
|
+
}
|
145
|
+
}
|
146
|
+
puts "after client in test message"
|
147
|
+
sleep 1
|
148
|
+
@f.tear_down_bunny
|
149
|
+
assert MessageFlag.testval==7, "should receive 7 message and set temp #{MessageFlag.testval}"
|
150
|
+
|
151
|
+
|
152
|
+
t1.exit
|
153
|
+
t2.exit
|
154
|
+
|
155
|
+
end
|
76
156
|
def test_client
|
157
|
+
puts "test client -- basic"
|
77
158
|
cmdhash={'command'=>'testdelegate2', 'promotion'=>2.to_s}
|
78
159
|
puts "----> to system [x] sending #{cmdhash.inspect}"
|
79
|
-
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => '
|
160
|
+
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testqueue7', :blocking => true, :consumer_name => "test consumer"}
|
80
161
|
bunny=EstormMessageProcessor::Client.new
|
81
162
|
assert bunny!=nil, "bunny should not be nil"
|
82
163
|
bunny.bunny_send_no_close(config[:url],config[:connnecturlflag],config[:queuename],cmdhash)
|
@@ -86,6 +167,29 @@ class EstormMessageProcessTest < Minitest::Test
|
|
86
167
|
end
|
87
168
|
|
88
169
|
|
170
|
+
#def test_one_shotclient
|
171
|
+
# assert MessageFlag.flag==false, "should be flase #{MessageFlag.inspect}"
|
172
|
+
# config={:url => 'fakeurl',:exit_when_empty => true,:connecturlflag=> false,:queuename => 'testqueue', :blocking => true}
|
173
|
+
# Thread.new {
|
174
|
+
|
175
|
+
# cmdhash={'command'=>'testdelegate2', 'temp'=>'temp'}
|
176
|
+
# puts "----> to system [x] sending 5 messages #{cmdhash.inspect}"
|
177
|
+
# 1.upto(5) {|i| # send five messages
|
178
|
+
# bunny=EstormMessageProcessor::Client.new
|
179
|
+
# bunny.bunny_send(config[:url],config[:connnecturlflag],config[:queuename],cmdhash)
|
180
|
+
# puts "after bunny send" }
|
181
|
+
# }
|
182
|
+
# sleep 2
|
183
|
+
|
184
|
+
# @f.start(config)
|
185
|
+
# sleep 10
|
186
|
+
|
187
|
+
# assert MessageFlag.testval==5, "should receive 5 message and set #{MessageFlag.inspect}"
|
188
|
+
# @f.tear_down_bunny
|
189
|
+
|
190
|
+
#end
|
191
|
+
|
192
|
+
|
89
193
|
|
90
194
|
|
91
195
|
|
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.
|
4
|
+
version: 0.1.6
|
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-
|
11
|
+
date: 2013-10-16 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
|
@@ -18,6 +18,7 @@ extra_rdoc_files: []
|
|
18
18
|
files:
|
19
19
|
- lib/estorm-message-processor/base.rb
|
20
20
|
- lib/estorm-message-processor/client.rb
|
21
|
+
- lib/estorm-message-processor/consumer.rb
|
21
22
|
- lib/estorm-message-processor.rb
|
22
23
|
- test/coverage/assets/0.7.1/application.css
|
23
24
|
- test/coverage/assets/0.7.1/application.js
|
@@ -60,6 +61,7 @@ files:
|
|
60
61
|
- test/coverage/assets/0.7.1/smoothness/images/ui-icons_888888_256x240.png
|
61
62
|
- test/coverage/assets/0.7.1/smoothness/images/ui-icons_cd0a0a_256x240.png
|
62
63
|
- test/coverage/index.html
|
64
|
+
- test/test_consumer.rb
|
63
65
|
- test/test_estorm.rb
|
64
66
|
- test/test_helper.rb
|
65
67
|
- Gemfile
|
@@ -75,12 +77,12 @@ require_paths:
|
|
75
77
|
- lib
|
76
78
|
required_ruby_version: !ruby/object:Gem::Requirement
|
77
79
|
requirements:
|
78
|
-
- - '>='
|
80
|
+
- - ! '>='
|
79
81
|
- !ruby/object:Gem::Version
|
80
82
|
version: '0'
|
81
83
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
84
|
requirements:
|
83
|
-
- - '>='
|
85
|
+
- - ! '>='
|
84
86
|
- !ruby/object:Gem::Version
|
85
87
|
version: 1.3.4
|
86
88
|
requirements: []
|