huck 0.2.5 → 0.3.0
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.
- checksums.yaml +4 -4
- data/lib/huck/receiver.rb +3 -7
- data/lib/huck/receivers/rabbitmq.rb +49 -0
- data/lib/huck/sender.rb +3 -7
- data/lib/huck/senders/rabbitmq.rb +52 -0
- data/lib/huck/version.rb +1 -1
- data/lib/huck.rb +2 -0
- data/spec/huck/util_spec.rb +15 -0
- metadata +15 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca3bf22a8ff5affb95d7bb88e7d40aa58e8077ab
|
4
|
+
data.tar.gz: ed30d1fedd87e7cc62b4942a7247323c57a77265
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc300e2459538853941313c9352fed1ba7b661530dce80da41c9eb18a36991b1581918e4f206934603f979b5819d170a70dce7095fa8b8bc4bb8f5ab565091b7
|
7
|
+
data.tar.gz: 80592af74c45e1eb246f20b1b99acfdedf363e8ef9adef532c3b918628523b2b4512805f9f0ca22c27950a2b50f9ec199e2ac06ac00f3867051b7d8233c80901
|
data/lib/huck/receiver.rb
CHANGED
@@ -19,17 +19,13 @@ module Huck
|
|
19
19
|
name = Huck::getarg kwargs, :name, nil
|
20
20
|
config = Huck::getarg kwargs, :config, nil
|
21
21
|
|
22
|
-
if name.nil?
|
23
|
-
if Huck::try_load 'aws-sdk'
|
24
|
-
name = 'sqs'
|
25
|
-
else
|
26
|
-
raise RuntimeError, 'unable to load any receivers'
|
27
|
-
end
|
28
|
-
end
|
22
|
+
name = 'sqs' if name.nil?
|
29
23
|
|
30
24
|
case name
|
31
25
|
when 'sqs'
|
32
26
|
r = Receivers::SQSReceiver.new
|
27
|
+
when 'rabbitmq'
|
28
|
+
r = Receivers::RabbitMQReceiver.new
|
33
29
|
else
|
34
30
|
raise RuntimeError, "bad receiver: #{name}"
|
35
31
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Huck
|
2
|
+
|
3
|
+
module Receivers
|
4
|
+
|
5
|
+
# A receiver that talks to RabbitMQ
|
6
|
+
class RabbitMQReceiver < Receiver
|
7
|
+
|
8
|
+
# Includes all required modules for the RabbitMQ receiver
|
9
|
+
def initialize
|
10
|
+
Huck::must_load 'bunny'
|
11
|
+
end
|
12
|
+
|
13
|
+
# Ensures that configuration is set properly before trying to use the
|
14
|
+
# connection data to talk to RabbitMQ
|
15
|
+
def verify_config
|
16
|
+
if !@config.has_key? 'rabbitmq'
|
17
|
+
raise RuntimeError, 'missing rabbitmq config'
|
18
|
+
end
|
19
|
+
if !@config['rabbitmq'].has_key? 'queue_name'
|
20
|
+
raise RuntimeError, 'missing rabbitmq receiver config: queue_name'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# A long-running poller process which reads messages out of the remote
|
25
|
+
# queue and yields them to higher-order logic.
|
26
|
+
def receive
|
27
|
+
verify_config
|
28
|
+
|
29
|
+
options = Hash.new
|
30
|
+
[:host, :port, :user, :pass, :vhost].each do |arg|
|
31
|
+
if @config['rabbitmq'].has_key? arg.to_s
|
32
|
+
options[arg] = @config['rabbitmq'][arg.to_s]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
conn = Bunny.new options
|
37
|
+
conn.start
|
38
|
+
|
39
|
+
ch = conn.create_channel
|
40
|
+
queue = ch.queue(@config['rabbitmq']['queue_name'])
|
41
|
+
|
42
|
+
queue.subscribe :block => true do |_, _, msg|
|
43
|
+
yield msg
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/huck/sender.rb
CHANGED
@@ -19,17 +19,13 @@ module Huck
|
|
19
19
|
name = Huck::getarg kwargs, :name, nil
|
20
20
|
config = Huck::getarg kwargs, :config, nil
|
21
21
|
|
22
|
-
if name.nil?
|
23
|
-
if Huck::try_load 'aws-sdk'
|
24
|
-
name = 'sqs'
|
25
|
-
else
|
26
|
-
raise RuntimeError, 'unable to load any senders'
|
27
|
-
end
|
28
|
-
end
|
22
|
+
name = 'sqs' if name.nil?
|
29
23
|
|
30
24
|
case name
|
31
25
|
when 'sqs'
|
32
26
|
s = Senders::SQSSender.new
|
27
|
+
when 'rabbitmq'
|
28
|
+
s = Senders::RabbitMQSender.new
|
33
29
|
else
|
34
30
|
raise RuntimeError, "bad sender: #{name}"
|
35
31
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Huck
|
2
|
+
|
3
|
+
module Senders
|
4
|
+
|
5
|
+
# A sender that talks to RabbitMQ
|
6
|
+
class RabbitMQSender < Sender
|
7
|
+
|
8
|
+
# Includes all required modules for the RabbitMQ sender
|
9
|
+
def initialize
|
10
|
+
Huck::must_load 'bunny'
|
11
|
+
end
|
12
|
+
|
13
|
+
# Ensures that configuration is set properly before trying to use the
|
14
|
+
# connection data to talk to rabbitmq
|
15
|
+
def verify_config
|
16
|
+
if !@config.has_key? 'rabbitmq'
|
17
|
+
raise RuntimeError, 'missing rabbitmq sender config'
|
18
|
+
end
|
19
|
+
if !@config['rabbitmq'].has_key? 'queue_name'
|
20
|
+
raise RuntimeError, 'missing rabbitmq sender config: queue_name'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Send an arbitrary text message to the queue for processing
|
25
|
+
#
|
26
|
+
# == Parameters:
|
27
|
+
# msg::
|
28
|
+
# The message to process
|
29
|
+
#
|
30
|
+
def send msg
|
31
|
+
verify_config
|
32
|
+
|
33
|
+
options = Hash.new
|
34
|
+
[:host, :port, :user, :pass, :vhost].each do |arg|
|
35
|
+
if @config['rabbitmq'].has_key? arg.to_s
|
36
|
+
options[arg] = @config['rabbitmq'][arg.to_s]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
conn = Bunny.new options
|
41
|
+
conn.start
|
42
|
+
|
43
|
+
ch = conn.create_channel
|
44
|
+
queue = ch.queue(@config['rabbitmq']['queue_name'])
|
45
|
+
xfer = ch.default_exchange
|
46
|
+
|
47
|
+
xfer.publish msg, :routing_key => @config['rabbitmq']['queue_name']
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
data/lib/huck/version.rb
CHANGED
data/lib/huck.rb
CHANGED
@@ -11,8 +11,10 @@ require 'huck/generators/yaml'
|
|
11
11
|
require 'huck/generators/json'
|
12
12
|
require 'huck/sender'
|
13
13
|
require 'huck/senders/sqs'
|
14
|
+
require 'huck/senders/rabbitmq'
|
14
15
|
require 'huck/receiver'
|
15
16
|
require 'huck/receivers/sqs'
|
17
|
+
require 'huck/receivers/rabbitmq'
|
16
18
|
require 'huck/handler'
|
17
19
|
require 'huck/handlers/echo'
|
18
20
|
require 'huck/handlers/exec'
|
data/spec/huck/util_spec.rb
CHANGED
@@ -34,4 +34,19 @@ describe 'Module Loading' do
|
|
34
34
|
it 'should raise a RuntimeError when module cannot be loaded' do
|
35
35
|
expect{Huck::must_load 'nonexistent'}.to raise_error(RuntimeError)
|
36
36
|
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'Data Serialization' do
|
41
|
+
input = {'a' => 'b'}
|
42
|
+
|
43
|
+
it 'should serialize to json' do
|
44
|
+
output = JSON.dump input
|
45
|
+
expect(Huck::serialize(input, :format => 'json')).to eq(output)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'should serialize to yaml' do
|
49
|
+
output = YAML.dump input
|
50
|
+
expect(Huck::serialize(input, :format => 'yaml')).to eq(output)
|
51
|
+
end
|
37
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: huck
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Uber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -59,23 +59,25 @@ executables:
|
|
59
59
|
extensions: []
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
|
-
- bin/huck
|
63
|
-
- lib/huck/generator.rb
|
64
|
-
- lib/huck/generators/basic.rb
|
65
|
-
- lib/huck/generators/facter.rb
|
66
|
-
- lib/huck/generators/json.rb
|
67
62
|
- lib/huck/generators/ohai.rb
|
63
|
+
- lib/huck/generators/facter.rb
|
64
|
+
- lib/huck/generators/basic.rb
|
68
65
|
- lib/huck/generators/yaml.rb
|
69
|
-
- lib/huck/
|
70
|
-
- lib/huck/
|
71
|
-
- lib/huck/
|
66
|
+
- lib/huck/generators/json.rb
|
67
|
+
- lib/huck/senders/sqs.rb
|
68
|
+
- lib/huck/senders/rabbitmq.rb
|
72
69
|
- lib/huck/receiver.rb
|
73
|
-
- lib/huck/receivers/sqs.rb
|
74
70
|
- lib/huck/sender.rb
|
75
|
-
- lib/huck/senders/sqs.rb
|
76
71
|
- lib/huck/util.rb
|
72
|
+
- lib/huck/generator.rb
|
73
|
+
- lib/huck/receivers/sqs.rb
|
74
|
+
- lib/huck/receivers/rabbitmq.rb
|
75
|
+
- lib/huck/handlers/exec.rb
|
76
|
+
- lib/huck/handlers/echo.rb
|
77
77
|
- lib/huck/version.rb
|
78
|
+
- lib/huck/handler.rb
|
78
79
|
- lib/huck.rb
|
80
|
+
- bin/huck
|
79
81
|
- spec/huck/util_spec.rb
|
80
82
|
- spec/spec_helper.rb
|
81
83
|
homepage: https://github.com/ryanuber/huck
|
@@ -98,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
98
100
|
version: '0'
|
99
101
|
requirements: []
|
100
102
|
rubyforge_project:
|
101
|
-
rubygems_version: 2.
|
103
|
+
rubygems_version: 2.1.11
|
102
104
|
signing_key:
|
103
105
|
specification_version: 4
|
104
106
|
summary: Information sharing framework
|