estorm-message-processor 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +29 -0
- data/README.md +13 -0
- data/lib/estorm-message-processor/base.rb +100 -0
- data/lib/estorm-message-processor.rb +7 -0
- data/test/test_estorm.rb +84 -0
- data/test/test_helper.rb +17 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
Y2JjZmEzMTNjNTY5MTk1YmEzOTZlMWFkNjE0OGNiODdiMThiODMwOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NzdkOTI1MTk0NzlmOWQzYTg5NDA3NjFhOTcwNmU5MTkyMDVlMTM5OA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZmU5MGFkODE2NzFhMWUyMTgyZTdkMmMyMjIzMDAzNWMyMzMyOTQyNWI3NWY2
|
10
|
+
NjI1MjE5NjVlYmIxZDAxMWE3YjZiN2M1NDEzNjQ3MzllOWZhY2ZjMWNjZWEz
|
11
|
+
ODJlYWRmNDRkMjA2YzQ1ZGYzNWEzY2JjMjdjM2MxMGJkYzM3YmU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
YjQyYjMyZjc2YmQwNTE5MzYxZDgzMjUzOTVmNGY3YmQ0NWZhNDExZDhmMDA2
|
14
|
+
YjdmNmRhYzQxYjI1ZmQ1YTE1ZjUzMDhkMzk2MjE2ZGVmOTViNzczYTRkNGVh
|
15
|
+
ZWUxOThhMmI5NGE4NDE0N2QzM2QzMDViYzE3NGQ2YTA1Y2VmZDI=
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
estorm-message-processor (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
amq-protocol (1.7.0)
|
10
|
+
bunny (0.10.7)
|
11
|
+
amq-protocol (>= 1.6.0)
|
12
|
+
codeclimate-test-reporter (0.1.1)
|
13
|
+
simplecov (>= 0.7.1, < 1.0.0)
|
14
|
+
minitest (5.0.8)
|
15
|
+
multi_json (1.8.0)
|
16
|
+
simplecov (0.7.1)
|
17
|
+
multi_json (~> 1.0)
|
18
|
+
simplecov-html (~> 0.7.1)
|
19
|
+
simplecov-html (0.7.1)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
bunny
|
26
|
+
codeclimate-test-reporter
|
27
|
+
estorm-message-processor!
|
28
|
+
minitest
|
29
|
+
multi_json
|
data/README.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/semdinsp/randprize.png)](https://travis-ci.org/semdinsp/randprize)
|
2
|
+
[![Code Climate](https://codeclimate.com/repos/524654d9c7f3a31b29038e3a/badges/58ed8386e3e6d266c7ac/gpa.png)](https://codeclimate.com/repos/524654d9c7f3a31b29038e3a/feed)
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/estorm-message-processor.png)](http://badge.fury.io/rb/estorm-message-processor)
|
4
|
+
|
5
|
+
estorm-message-processor gem
|
6
|
+
============
|
7
|
+
|
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
|
10
|
+
|
11
|
+
Usage
|
12
|
+
=======
|
13
|
+
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bunny'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module EstormMessageProcessor
|
6
|
+
class Base
|
7
|
+
|
8
|
+
# MT id counter.
|
9
|
+
@@mt_id = 0
|
10
|
+
def Base.logger
|
11
|
+
@@logger
|
12
|
+
end
|
13
|
+
|
14
|
+
def Base.logger=(logger)
|
15
|
+
@@logger = logger
|
16
|
+
end
|
17
|
+
|
18
|
+
def logger
|
19
|
+
@@logger
|
20
|
+
end
|
21
|
+
|
22
|
+
def process_messages(delivery_info,properties,body)
|
23
|
+
begin
|
24
|
+
msg = "-----> [bunny_contact_processor] Received from App #{body} "
|
25
|
+
logger.info msg
|
26
|
+
cmdhash=YAML.load(body)
|
27
|
+
delegatestring="delegate_#{cmdhash['command']}"
|
28
|
+
# create procedures named delegate_command accepting cmdhash
|
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
|
38
|
+
|
39
|
+
def logger
|
40
|
+
EstormMessageProcessor::Base.logger
|
41
|
+
end
|
42
|
+
|
43
|
+
def setup_bunny_communications(url,flag,queuename)
|
44
|
+
begin
|
45
|
+
# pass flag in as Rails.env.production?
|
46
|
+
@client = Bunny.new(url) if flag
|
47
|
+
@client = Bunny.new if !flag
|
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
|
57
|
+
@queue = @channel.queue(queuename)
|
58
|
+
msg= "set up active MQ on #{queuename}"
|
59
|
+
logger.info msg
|
60
|
+
end
|
61
|
+
|
62
|
+
def tear_down_bunny
|
63
|
+
@client.close if @client!=nil
|
64
|
+
msg= "closing bunny"
|
65
|
+
logger.info msg
|
66
|
+
end
|
67
|
+
|
68
|
+
def start(config)
|
69
|
+
setup_bunny_communications(config[:url],config[:connecturlflag],config[:queuename])
|
70
|
+
# Run EventMachine in loop so we can reconnect when the SMSC drops our connection.
|
71
|
+
msg= "Connecting to bunny #{config.inspect} environment #{config.inspect}"
|
72
|
+
logger.info msg
|
73
|
+
loop do
|
74
|
+
|
75
|
+
|
76
|
+
msg= "[*] Waiting for messages in #{@queue.name}. blocking is #{config[:blocking]}"
|
77
|
+
logger.info msg
|
78
|
+
@queue.subscribe(:block => config[:blocking]) do |delivery_info, properties, body|
|
79
|
+
process_messages(delivery_info,properties,body)
|
80
|
+
# cancel the consumer to exit
|
81
|
+
#delivery_info.consumer.cancel
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
msg= "Disconnected. Reconnecting in 5 seconds.."
|
86
|
+
logger.info msg
|
87
|
+
#puts msg
|
88
|
+
tear_down_bunny
|
89
|
+
sleep 1
|
90
|
+
setup_bunny_communications
|
91
|
+
sleep 4
|
92
|
+
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
end
|
100
|
+
end #Module
|
@@ -0,0 +1,7 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
Dir[File.join(File.dirname(__FILE__), 'estorm-message-processor/**/*.rb')].sort.each { |lib| require lib }
|
4
|
+
|
5
|
+
module EstormMessageProcessor
|
6
|
+
VERSION = '0.0.1'
|
7
|
+
end
|
data/test/test_estorm.rb
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
puts File.dirname(__FILE__)
|
2
|
+
require 'yaml'
|
3
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
4
|
+
class MessageFlag
|
5
|
+
@@flag=false
|
6
|
+
def self.setflag
|
7
|
+
@@flag=true
|
8
|
+
end
|
9
|
+
def self.flag
|
10
|
+
@@flag
|
11
|
+
end
|
12
|
+
end
|
13
|
+
class EstormMessageProcessor::Base
|
14
|
+
def delegate_testdelegate(cmdhash)
|
15
|
+
puts "teste delegate received #{cmdhash.inspect}"
|
16
|
+
MessageFlag.setflag
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
class EstormMessageProcessTest < Minitest::Test
|
22
|
+
|
23
|
+
def setup
|
24
|
+
EstormMessageProcessor::Base.logger=Logger.new(STDERR)
|
25
|
+
@f=EstormMessageProcessor::Base.new
|
26
|
+
@@temp=false
|
27
|
+
puts "after setup"
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_basic
|
31
|
+
assert @f!=nil, "should be valid"
|
32
|
+
assert !@@temp, "should be false"
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_startup
|
36
|
+
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testqueue', :blocking => true}
|
37
|
+
Thread.new {
|
38
|
+
@f.start(config) }
|
39
|
+
sleep(15)
|
40
|
+
@f.tear_down_bunny
|
41
|
+
assert true,"should get here"
|
42
|
+
end
|
43
|
+
def test_1yaml
|
44
|
+
puts "in yaml test"
|
45
|
+
fred={'test' => 'fredtest'}
|
46
|
+
yaml=fred.to_yaml
|
47
|
+
assert yaml.include?('test'), "should have test in it"
|
48
|
+
loaded=YAML.load(yaml)
|
49
|
+
assert loaded['test']==fred['test'],"values should be smae"
|
50
|
+
end
|
51
|
+
def test_message
|
52
|
+
assert MessageFlag.flag==false, "should be flase #{MessageFlag.inspect}"
|
53
|
+
config={:url => 'fakeurl',:connecturlflag=> false,:queuename => 'testqueue', :blocking => true}
|
54
|
+
Thread.new {
|
55
|
+
@f.start(config) }
|
56
|
+
sleep(20)
|
57
|
+
puts "after start in test message"
|
58
|
+
Thread.new {
|
59
|
+
conn = Bunny.new
|
60
|
+
conn.start
|
61
|
+
|
62
|
+
channel = conn.create_channel
|
63
|
+
#puts "connected: #{conn.inspect}"
|
64
|
+
puts "bunny sender establisedh"
|
65
|
+
queue = channel.queue(config[:queuename])
|
66
|
+
assert queue!=nil, "queue should be valid"
|
67
|
+
cmdhash={'command'=>'testdelegate', 'temp'=>'temp'}
|
68
|
+
puts "about to sende message"
|
69
|
+
channel.default_exchange.publish(cmdhash.to_yaml, :routing_key => queue.name)
|
70
|
+
puts "----> to system [x] sending #{cmdhash.inspect}"
|
71
|
+
conn.close
|
72
|
+
}
|
73
|
+
puts "after client in test message"
|
74
|
+
sleep 5
|
75
|
+
assert MessageFlag.flag==true, "should receive message and set temp #{MessageFlag.inspect}"
|
76
|
+
@f.tear_down_bunny
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
puts "in test helper"
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler/setup'
|
4
|
+
require "codeclimate-test-reporter"
|
5
|
+
CodeClimate::TestReporter.start
|
6
|
+
require 'stringio'
|
7
|
+
require 'minitest/autorun'
|
8
|
+
require 'minitest/unit'
|
9
|
+
SimpleCov.command_name 'test'
|
10
|
+
#SimpleCov.profiles.define 'mygem' do
|
11
|
+
# add_group "Gem", '/lib/' # additional config here
|
12
|
+
#end
|
13
|
+
SimpleCov.start
|
14
|
+
|
15
|
+
require File.dirname(__FILE__) + '/../lib/estorm-message-processor'
|
16
|
+
|
17
|
+
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: estorm-message-processor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Sproule
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-12 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: a gem to help rails app process AMQP queues for background jobs
|
14
|
+
email: scott.sproule@ficonab.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/estorm-message-processor/base.rb
|
20
|
+
- lib/estorm-message-processor.rb
|
21
|
+
- test/test_estorm.rb
|
22
|
+
- test/test_helper.rb
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- README.md
|
26
|
+
homepage: http://github.com/semdinsp/randprize
|
27
|
+
licenses:
|
28
|
+
- MIT
|
29
|
+
metadata: {}
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 1.3.4
|
44
|
+
requirements: []
|
45
|
+
rubyforge_project: estorm-message-processor
|
46
|
+
rubygems_version: 2.0.6
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: Using a AMQP to process a queue. Primarily support for scripting
|
50
|
+
test_files: []
|