sensu-transport 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.travis.yml +15 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +20 -0
- data/README.md +38 -0
- data/Rakefile +6 -0
- data/lib/sensu/transport.rb +12 -0
- data/lib/sensu/transport/base.rb +141 -0
- data/lib/sensu/transport/rabbitmq.rb +133 -0
- data/sensu-transport.gemspec +24 -0
- data/spec/base_spec.rb +38 -0
- data/spec/helpers.rb +24 -0
- data/spec/rabbitmq_spec.rb +83 -0
- data/spec/transport_spec.rb +17 -0
- metadata +132 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aa4dd8fe1cfdf292bd43c1eb1a9e9e48f8364ff3
|
4
|
+
data.tar.gz: 0c6d0e95c66e6178440a01735fd9e010c0e1f078
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 589b4ac0df3a423c9560643c87ebf75b6f85259fc126c482511050f31e0472f3c9e8e8e7b3538ac8a3c9d2c30edee5e2b4980bb766d950c386a1b4242be946f5
|
7
|
+
data.tar.gz: 2c145d6f1cd357ec5dcfb737ddf1bd3cf130067e5491f572da15e58d50302550cc94f5751e8e69cdb5d64f5b10514e82a944d9f1fbc44025f04ab9d0c87ce014
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2014 Heavy Water Operations.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# Sensu::Transport
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/sensu/sensu-transport.svg?branch=master)](https://travis-ci.org/sensu/sensu-transport)
|
4
|
+
|
5
|
+
[![Code Climate](https://codeclimate.com/github/sensu/sensu-transport.png)](https://codeclimate.com/github/sensu/sensu-transport)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'sensu-transport'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
This library provides the transport Base class, its documentation can be found
|
20
|
+
[here](http://rubydoc.info/github/sensu/sensu-transport/Sensu/Transport/Base).
|
21
|
+
The RabbitMQ transport is also included, providing an example while
|
22
|
+
continuing to be the primary Sensu transport, supported by the
|
23
|
+
community and [Heavy Water Operations](http://hw-ops.com).
|
24
|
+
|
25
|
+
## Contributing
|
26
|
+
|
27
|
+
Please do not submit a pull request to add an additional transport to
|
28
|
+
this library.
|
29
|
+
|
30
|
+
1. [Fork it](https://github.com/sensu/sensu-transport/fork)
|
31
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
32
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
33
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
34
|
+
5. Create a new Pull Request
|
35
|
+
|
36
|
+
## License
|
37
|
+
|
38
|
+
Sensu-Transport is released under the [MIT license](https://raw.github.com/sensu/sensu-transport/master/LICENSE.txt).
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module Sensu
|
2
|
+
module Transport
|
3
|
+
def self.connect(transport, options={})
|
4
|
+
require("sensu/transport/#{transport}")
|
5
|
+
klass = Base.descendants.detect do |klass|
|
6
|
+
klass.name.downcase.split("::").last == transport
|
7
|
+
end
|
8
|
+
object = klass.connect(options)
|
9
|
+
object
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
module Sensu
|
2
|
+
module Transport
|
3
|
+
class Error < StandardError; end
|
4
|
+
|
5
|
+
class Base
|
6
|
+
# @!attribute [rw] logger
|
7
|
+
# @return [Logger] the Sensu logger object.
|
8
|
+
attr_accessor :logger
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@on_error = Proc.new {}
|
12
|
+
@before_reconnect = Proc.new {}
|
13
|
+
@after_reconnect = Proc.new {}
|
14
|
+
end
|
15
|
+
|
16
|
+
# Sets the error callback.
|
17
|
+
#
|
18
|
+
# @param callback [Proc] called in the event of a transport
|
19
|
+
# error, the exception object should be passed as a parameter.
|
20
|
+
# @return [Proc] the error callback.
|
21
|
+
def on_error(&callback)
|
22
|
+
@on_error = callback
|
23
|
+
end
|
24
|
+
|
25
|
+
# Sets the before reconnect callback.
|
26
|
+
#
|
27
|
+
# @param callback [Proc] called before attempting to reconnect
|
28
|
+
# to the transport.
|
29
|
+
# @return [Proc] the before reconnect callback.
|
30
|
+
def before_reconnect(&callback)
|
31
|
+
@before_reconnect = callback
|
32
|
+
end
|
33
|
+
|
34
|
+
# Sets the after reconnect callback.
|
35
|
+
#
|
36
|
+
# @param callback [Proc] called after reconnecting to the
|
37
|
+
# transport.
|
38
|
+
# @return [Proc] the after reconnect callback.
|
39
|
+
def after_reconnect(&callback)
|
40
|
+
@after_reconnect = callback
|
41
|
+
end
|
42
|
+
|
43
|
+
# Transport connection setup.
|
44
|
+
#
|
45
|
+
# @param options [Hash, String]
|
46
|
+
def connect(options={}); end
|
47
|
+
|
48
|
+
# Indicates if connected to the transport.
|
49
|
+
#
|
50
|
+
# @return [TrueClass, FalseClass]
|
51
|
+
def connected?
|
52
|
+
false
|
53
|
+
end
|
54
|
+
|
55
|
+
# Close the transport connection.
|
56
|
+
def close; end
|
57
|
+
|
58
|
+
# Connects to the transport.
|
59
|
+
#
|
60
|
+
# @param options [Hash, String]
|
61
|
+
# @return [Transport] the transport object.
|
62
|
+
def self.connect(options={})
|
63
|
+
options ||= {}
|
64
|
+
transport = self.new
|
65
|
+
transport.connect(options)
|
66
|
+
transport
|
67
|
+
end
|
68
|
+
|
69
|
+
# Publish a message to the transport.
|
70
|
+
#
|
71
|
+
# @param type [Symbol] the transport pipe type, possible values
|
72
|
+
# are: :direct and :fanout.
|
73
|
+
# @param pipe [String] the transport pipe name.
|
74
|
+
# @param message [String] the message to be published to the transport.
|
75
|
+
# @param options [Hash] the options to publish the message with.
|
76
|
+
# @yield [info] passes publish info to an optional callback/block.
|
77
|
+
# @yieldparam info [Hash] contains publish information, which
|
78
|
+
# may contain an error object.
|
79
|
+
def publish(type, pipe, message, options={}, &callback)
|
80
|
+
info = {:error => nil}
|
81
|
+
callback.call(info) if callback
|
82
|
+
end
|
83
|
+
|
84
|
+
# Subscribe to a transport pipe and/or funnel.
|
85
|
+
#
|
86
|
+
# @param type [Symbol] the transport pipe type, possible values
|
87
|
+
# are: :direct and :fanout.
|
88
|
+
# @param pipe [String] the transport pipe name.
|
89
|
+
# @param funnel [String] the transport funnel, which may be
|
90
|
+
# connected to multiple pipes.
|
91
|
+
# @param options [Hash] the options to consume messages with.
|
92
|
+
# @yield [info, message] passes message info and content to
|
93
|
+
# the consumer callback/block.
|
94
|
+
# @yieldparam info [Hash] contains message information.
|
95
|
+
# @yieldparam message [String] message.
|
96
|
+
def subscribe(type, pipe, funnel=nil, options={}, &callback)
|
97
|
+
info = {}
|
98
|
+
message = ''
|
99
|
+
callback.call(info, message)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Unsubscribe from all transport pipes and/or funnels.
|
103
|
+
#
|
104
|
+
# @yield [info] passes info to an optional callback/block.
|
105
|
+
# @yieldparam info [Hash] contains unsubscribe information.
|
106
|
+
def unsubscribe(&callback)
|
107
|
+
info = {}
|
108
|
+
callback.call(info) if callback
|
109
|
+
end
|
110
|
+
|
111
|
+
# Acknowledge the delivery of a message from the transport.
|
112
|
+
#
|
113
|
+
# @param info [Hash] message information, eg. contains its id.
|
114
|
+
# @yield [info] passes acknowledgment info to an optional callback/block.
|
115
|
+
def acknowledge(info, &callback)
|
116
|
+
callback.call(info) if callback
|
117
|
+
end
|
118
|
+
|
119
|
+
# Alias for acknowledge()
|
120
|
+
def ack(*args, &callback)
|
121
|
+
acknowledge(*args, &callback)
|
122
|
+
end
|
123
|
+
|
124
|
+
# Transport funnel stats, such as message and consumer counts.
|
125
|
+
#
|
126
|
+
# @param funnel [String] the transport funnel to get stats for.
|
127
|
+
# @param options [Hash] the options to get funnel stats with.
|
128
|
+
def stats(funnel, options={}, &callback)
|
129
|
+
info = {}
|
130
|
+
callback.call(info)
|
131
|
+
end
|
132
|
+
|
133
|
+
# Discover available transports (Subclasses)
|
134
|
+
def self.descendants
|
135
|
+
ObjectSpace.each_object(Class).select do |klass|
|
136
|
+
klass < self
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
gem "amqp", "1.3.0"
|
2
|
+
|
3
|
+
require "amqp"
|
4
|
+
|
5
|
+
require File.join(File.dirname(__FILE__), "base")
|
6
|
+
|
7
|
+
module Sensu
|
8
|
+
module Transport
|
9
|
+
class RabbitMQ < Base
|
10
|
+
def initialize
|
11
|
+
super
|
12
|
+
@queues = {}
|
13
|
+
end
|
14
|
+
|
15
|
+
def connect(options={})
|
16
|
+
timeout = create_connection_timeout
|
17
|
+
on_failure = on_connection_failure
|
18
|
+
@connection = AMQP.connect(options, {
|
19
|
+
:on_tcp_connection_failure => on_failure,
|
20
|
+
:on_possible_authentication_failure => on_failure
|
21
|
+
})
|
22
|
+
@connection.logger = @logger
|
23
|
+
@connection.on_open do
|
24
|
+
timeout.cancel
|
25
|
+
end
|
26
|
+
reconnect = Proc.new do
|
27
|
+
unless @connection.reconnecting?
|
28
|
+
@before_reconnect.call
|
29
|
+
@connection.periodically_reconnect(5)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
@connection.on_tcp_connection_loss(&reconnect)
|
33
|
+
@connection.on_skipped_heartbeats(&reconnect)
|
34
|
+
setup_channel(options)
|
35
|
+
end
|
36
|
+
|
37
|
+
def connected?
|
38
|
+
@connection.connected?
|
39
|
+
end
|
40
|
+
|
41
|
+
def close
|
42
|
+
@connection.close
|
43
|
+
end
|
44
|
+
|
45
|
+
def publish(exchange_type, exchange_name, message, options={}, &callback)
|
46
|
+
begin
|
47
|
+
@channel.method(exchange_type.to_sym).call(exchange_name, options).publish(message) do
|
48
|
+
info = {}
|
49
|
+
callback.call(info) if callback
|
50
|
+
end
|
51
|
+
rescue => error
|
52
|
+
info = {:error => error}
|
53
|
+
callback.call(info) if callback
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def subscribe(exchange_type, exchange_name, queue_name="", options={}, &callback)
|
58
|
+
previously_declared = @queues.has_key?(queue_name)
|
59
|
+
@queues[queue_name] ||= @channel.queue!(queue_name, :auto_delete => true)
|
60
|
+
queue = @queues[queue_name]
|
61
|
+
queue.bind(@channel.method(exchange_type.to_sym).call(exchange_name))
|
62
|
+
unless previously_declared
|
63
|
+
queue.subscribe(options, &callback)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def unsubscribe(&callback)
|
68
|
+
@queues.values.each do |queue|
|
69
|
+
if connected?
|
70
|
+
queue.unsubscribe
|
71
|
+
else
|
72
|
+
queue.before_recovery do
|
73
|
+
queue.unsubscribe
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
@queues = {}
|
78
|
+
@channel.recover if connected?
|
79
|
+
super
|
80
|
+
end
|
81
|
+
|
82
|
+
def acknowledge(info, &callback)
|
83
|
+
info.ack
|
84
|
+
callback.call(info) if callback
|
85
|
+
end
|
86
|
+
|
87
|
+
def stats(queue_name, options={}, &callback)
|
88
|
+
options = options.merge(:auto_delete => true)
|
89
|
+
@channel.queue(queue_name, options).status do |messages, consumers|
|
90
|
+
info = {
|
91
|
+
:messages => messages,
|
92
|
+
:consumers => consumers
|
93
|
+
}
|
94
|
+
callback.call(info)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def create_connection_timeout
|
101
|
+
EM::Timer.new(20) do
|
102
|
+
error = Error.new("timed out while attempting to connect to rabbitmq")
|
103
|
+
@on_error.call(error)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def on_connection_failure
|
108
|
+
Proc.new do
|
109
|
+
error = Error.new("failed to connect to rabbitmq")
|
110
|
+
@on_error.call(error)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def setup_channel(options={})
|
115
|
+
@channel = AMQP::Channel.new(@connection)
|
116
|
+
@channel.auto_recovery = true
|
117
|
+
@channel.on_error do |channel, channel_close|
|
118
|
+
error = Error.new("rabbitmq channel closed")
|
119
|
+
@on_error.call(error)
|
120
|
+
end
|
121
|
+
prefetch = 1
|
122
|
+
if options.is_a?(Hash)
|
123
|
+
prefetch = options.fetch(:prefetch, 1)
|
124
|
+
end
|
125
|
+
@channel.on_recovery do
|
126
|
+
@after_reconnect.call
|
127
|
+
@channel.prefetch(prefetch)
|
128
|
+
end
|
129
|
+
@channel.prefetch(prefetch)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "sensu-transport"
|
5
|
+
spec.version = "0.0.1"
|
6
|
+
spec.authors = ["Sean Porter"]
|
7
|
+
spec.email = ["portertech@gmail.com"]
|
8
|
+
spec.summary = "The Sensu transport abstraction library"
|
9
|
+
spec.description = "The Sensu transport abstraction library"
|
10
|
+
spec.homepage = "https://github.com/sensu/sensu-transport"
|
11
|
+
spec.license = "MIT"
|
12
|
+
|
13
|
+
spec.files = `git ls-files -z`.split("\x0")
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
+
spec.require_paths = ["lib"]
|
17
|
+
|
18
|
+
spec.add_dependency("eventmachine")
|
19
|
+
spec.add_dependency("amqp", "1.3.0")
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
end
|
data/spec/base_spec.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "helpers")
|
2
|
+
require "sensu/transport/base"
|
3
|
+
|
4
|
+
describe "Sensu::Transport::Base" do
|
5
|
+
include Helpers
|
6
|
+
|
7
|
+
before do
|
8
|
+
@transport = Sensu::Transport::Base.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "provides a transport API (noop)" do
|
12
|
+
Sensu::Transport::Base.should respond_to(:connect)
|
13
|
+
@transport.should respond_to(:on_error, :before_reconnect, :after_reconnect,
|
14
|
+
:connect, :connected?, :close,
|
15
|
+
:publish, :subscribe, :unsubscribe, :stats)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "behaves as expected" do
|
19
|
+
callback = Proc.new { true }
|
20
|
+
@transport.on_error(&callback).should be_an_instance_of(Proc)
|
21
|
+
@transport.before_reconnect(&callback).should be_an_instance_of(Proc)
|
22
|
+
@transport.after_reconnect(&callback).should be_an_instance_of(Proc)
|
23
|
+
@transport.connect.should eq(nil)
|
24
|
+
@transport.connect({}).should eq(nil)
|
25
|
+
@transport.connected?.should eq(false)
|
26
|
+
@transport.close.should eq(nil)
|
27
|
+
@transport.publish("foo", "bar", "baz").should eq(nil)
|
28
|
+
@transport.publish("foo", "bar", "baz", {}, &callback).should eq(true)
|
29
|
+
@transport.subscribe("foo", "bar", nil, {}, &callback).should eq(true)
|
30
|
+
@transport.unsubscribe.should eq(nil)
|
31
|
+
@transport.unsubscribe(&callback).should eq(true)
|
32
|
+
@transport.acknowledge({}).should eq(nil)
|
33
|
+
@transport.ack({}).should eq(nil)
|
34
|
+
@transport.acknowledge({}, &callback).should eq(true)
|
35
|
+
@transport.ack({}, &callback).should eq(true)
|
36
|
+
@transport.stats("foo", &callback).should eq(true)
|
37
|
+
end
|
38
|
+
end
|
data/spec/helpers.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "rspec"
|
2
|
+
require "eventmachine"
|
3
|
+
|
4
|
+
module Helpers
|
5
|
+
def timer(delay, &callback)
|
6
|
+
periodic_timer = EM::PeriodicTimer.new(delay) do
|
7
|
+
callback.call
|
8
|
+
periodic_timer.cancel
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def async_wrapper(&callback)
|
13
|
+
EM::run do
|
14
|
+
timer(10) do
|
15
|
+
raise "test timed out"
|
16
|
+
end
|
17
|
+
callback.call
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def async_done
|
22
|
+
EM::stop_event_loop
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "helpers")
|
2
|
+
require "sensu/transport/rabbitmq"
|
3
|
+
|
4
|
+
describe "Sensu::Transport::RabbitMQ" do
|
5
|
+
include Helpers
|
6
|
+
|
7
|
+
before do
|
8
|
+
@transport = Sensu::Transport::RabbitMQ.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "provides a transport API" do
|
12
|
+
Sensu::Transport::RabbitMQ.should respond_to(:connect)
|
13
|
+
@transport.should respond_to(:on_error, :before_reconnect, :after_reconnect,
|
14
|
+
:connect, :connected?, :close,
|
15
|
+
:publish, :subscribe, :unsubscribe)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "can publish and subscribe" do
|
19
|
+
async_wrapper do
|
20
|
+
@transport.connect
|
21
|
+
callback = Proc.new do |message|
|
22
|
+
message.should eq("msg")
|
23
|
+
timer(0.5) do
|
24
|
+
async_done
|
25
|
+
end
|
26
|
+
end
|
27
|
+
@transport.subscribe("direct", "foo", "baz", {}, &callback)
|
28
|
+
@transport.subscribe("direct", "bar", "baz", {}, &callback)
|
29
|
+
timer(1) do
|
30
|
+
@transport.publish("direct", "foo", "msg") do |info|
|
31
|
+
info.should be_kind_of(Hash)
|
32
|
+
info.should be_empty
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
it "can unsubscribe from queues and close the connection" do
|
39
|
+
async_wrapper do
|
40
|
+
@transport.connect
|
41
|
+
@transport.subscribe("direct", "bar") do |info, message|
|
42
|
+
true
|
43
|
+
end
|
44
|
+
timer(1) do
|
45
|
+
@transport.unsubscribe do
|
46
|
+
@transport.close
|
47
|
+
async_done
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
it "can acknowledge the delivery of a message" do
|
54
|
+
async_wrapper do
|
55
|
+
@transport.connect
|
56
|
+
@transport.subscribe("direct", "foo", :ack => true) do |info, message|
|
57
|
+
@transport.acknowledge(info) do
|
58
|
+
timer(0.5) do
|
59
|
+
async_done
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
timer(1) do
|
64
|
+
@transport.publish("direct", "foo", "msg") do |info|
|
65
|
+
info.should be_kind_of(Hash)
|
66
|
+
info.should be_empty
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
it "can get queue stats, message and consumer counts" do
|
73
|
+
async_wrapper do
|
74
|
+
@transport.connect
|
75
|
+
@transport.stats("bar") do |info|
|
76
|
+
info.should be_kind_of(Hash)
|
77
|
+
info[:messages].should eq(0)
|
78
|
+
info[:consumers].should eq(0)
|
79
|
+
async_done
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "helpers")
|
2
|
+
require "sensu/transport"
|
3
|
+
|
4
|
+
describe "Sensu::Transport" do
|
5
|
+
include Helpers
|
6
|
+
|
7
|
+
it "can load and connect to the rabbitmq transport" do
|
8
|
+
async_wrapper do
|
9
|
+
options = {}
|
10
|
+
transport = Sensu::Transport.connect("rabbitmq", options)
|
11
|
+
timer(1) do
|
12
|
+
transport.connected?.should be_true
|
13
|
+
async_done
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-transport
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Porter
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: eventmachine
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: amqp
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.3.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.3.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.6'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.6'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: The Sensu transport abstraction library
|
84
|
+
email:
|
85
|
+
- portertech@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- lib/sensu/transport.rb
|
97
|
+
- lib/sensu/transport/base.rb
|
98
|
+
- lib/sensu/transport/rabbitmq.rb
|
99
|
+
- sensu-transport.gemspec
|
100
|
+
- spec/base_spec.rb
|
101
|
+
- spec/helpers.rb
|
102
|
+
- spec/rabbitmq_spec.rb
|
103
|
+
- spec/transport_spec.rb
|
104
|
+
homepage: https://github.com/sensu/sensu-transport
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.2.0
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: The Sensu transport abstraction library
|
128
|
+
test_files:
|
129
|
+
- spec/base_spec.rb
|
130
|
+
- spec/helpers.rb
|
131
|
+
- spec/rabbitmq_spec.rb
|
132
|
+
- spec/transport_spec.rb
|