rack-rabbit 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/EXAMPLES.md +2 -2
- data/Gemfile +7 -1
- data/Gemfile.lock +19 -11
- data/LICENSE +1 -1
- data/README.md +3 -3
- data/lib/rack-rabbit.rb +7 -1
- data/lib/rack-rabbit/adapter.rb +2 -0
- data/lib/rack-rabbit/adapter/mock.rb +10 -1
- data/lib/rack-rabbit/client.rb +3 -1
- data/lib/rack-rabbit/config.rb +4 -4
- data/lib/rack-rabbit/message.rb +2 -0
- data/lib/rack-rabbit/server.rb +1 -1
- data/lib/rack-rabbit/subscriber.rb +1 -1
- data/test/test_case.rb +16 -2
- data/test/unit/test_config.rb +3 -3
- data/test/unit/test_subscriber.rb +14 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d0ae6fe9017057176665a112219b20bcb02cf6c4
|
4
|
+
data.tar.gz: 643d99de440abf0344e63bbe6628acb55cfba3a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f24c11999c486fa2272ff592cc0a6fd2564d0a345102852375393952d8397646478b8178ed8153413e194a7cd3df74be9ee46a84059f3118874dad6d068b3d79
|
7
|
+
data.tar.gz: 7aa285b2a94b5ebafadd532df2f260523d636a8fe2f1ed1615fd977bbfc78284a2fd285014904a335f8aa33027e98061accf1dd88a64839b9ab94e48020cd2e6
|
data/EXAMPLES.md
CHANGED
@@ -154,7 +154,7 @@ First `foo.ru`
|
|
154
154
|
require 'sinatra/base'
|
155
155
|
|
156
156
|
class Foo < Sinatra::Base
|
157
|
-
post "/event do
|
157
|
+
post "/event" do
|
158
158
|
logger.info "Foo saw the event"
|
159
159
|
end
|
160
160
|
end
|
@@ -165,7 +165,7 @@ Then `bar.ru`
|
|
165
165
|
require 'sinatra/base'
|
166
166
|
|
167
167
|
class Bar < Sinatra::Base
|
168
|
-
post "/event do
|
168
|
+
post "/event" do
|
169
169
|
logger.info "Bar saw the event"
|
170
170
|
end
|
171
171
|
end
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -2,32 +2,33 @@ GEM
|
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
4
|
amq-protocol (1.9.2)
|
5
|
-
amqp (1.
|
6
|
-
amq-protocol (
|
5
|
+
amqp (1.5.1)
|
6
|
+
amq-protocol (~> 1.9)
|
7
7
|
eventmachine
|
8
|
-
bunny (
|
8
|
+
bunny (2.0.1)
|
9
9
|
amq-protocol (>= 1.9.2)
|
10
10
|
coderay (1.1.0)
|
11
|
-
eventmachine (1.0.
|
11
|
+
eventmachine (1.0.8)
|
12
12
|
metaclass (0.0.4)
|
13
13
|
method_source (0.8.2)
|
14
|
-
minitest (
|
14
|
+
minitest (5.10.3)
|
15
15
|
mocha (1.1.0)
|
16
16
|
metaclass (~> 0.0.1)
|
17
17
|
pry (0.10.1)
|
18
18
|
coderay (~> 1.1.0)
|
19
19
|
method_source (~> 0.8.1)
|
20
20
|
slop (~> 3.4)
|
21
|
-
rack (1.
|
21
|
+
rack (1.6.4)
|
22
22
|
rack-protection (1.5.3)
|
23
23
|
rack
|
24
|
-
|
24
|
+
rake (12.0.0)
|
25
|
+
sinatra (1.4.6)
|
25
26
|
rack (~> 1.4)
|
26
27
|
rack-protection (~> 1.4)
|
27
|
-
tilt (
|
28
|
+
tilt (>= 1.3, < 3)
|
28
29
|
slop (3.6.0)
|
29
|
-
tilt (
|
30
|
-
timecop (0.
|
30
|
+
tilt (2.0.1)
|
31
|
+
timecop (0.8.0)
|
31
32
|
|
32
33
|
PLATFORMS
|
33
34
|
ruby
|
@@ -35,8 +36,15 @@ PLATFORMS
|
|
35
36
|
DEPENDENCIES
|
36
37
|
amqp
|
37
38
|
bunny
|
38
|
-
minitest (~>
|
39
|
+
minitest (~> 5.10.3)
|
39
40
|
mocha
|
40
41
|
pry
|
42
|
+
rake
|
41
43
|
sinatra
|
42
44
|
timecop
|
45
|
+
|
46
|
+
RUBY VERSION
|
47
|
+
ruby 2.4.1p111
|
48
|
+
|
49
|
+
BUNDLED WITH
|
50
|
+
1.15.3
|
data/LICENSE
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
The MIT License (MIT)
|
2
2
|
|
3
|
-
Copyright (c) 2014 Jake Gordon
|
3
|
+
Copyright (c) 2014, 2015, 2016, 2017 Jake Gordon
|
4
4
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Rack Rabbit (v0.
|
1
|
+
# Rack Rabbit (v0.6.0)
|
2
2
|
|
3
3
|
A forking server for hosting rabbitMQ consumer processes as load balanced rack applications.
|
4
4
|
|
@@ -53,8 +53,8 @@ Install a rabbitMQ server if necessary ([docs](https://www.rabbitmq.com/download
|
|
53
53
|
|
54
54
|
Update your Gemfile to include RackRabbit and your preferred rabbitMQ client library
|
55
55
|
|
56
|
-
gem bunny, "~>
|
57
|
-
gem rack-rabbit, "~> 0.
|
56
|
+
gem bunny, "~> 2.7"
|
57
|
+
gem rack-rabbit, "~> 0.6"
|
58
58
|
|
59
59
|
|
60
60
|
## Getting started by example
|
data/lib/rack-rabbit.rb
CHANGED
@@ -4,7 +4,7 @@ module RackRabbit
|
|
4
4
|
# CONSTANTS
|
5
5
|
#============================================================================
|
6
6
|
|
7
|
-
VERSION = "0.
|
7
|
+
VERSION = "0.6.0"
|
8
8
|
SUMMARY = "A Unicorn-style forking, rack-based server for hosting rabbitMQ consumer processes"
|
9
9
|
|
10
10
|
DEFAULT_RABBIT = {
|
@@ -59,5 +59,11 @@ module RackRabbit
|
|
59
59
|
|
60
60
|
#----------------------------------------------------------------------------
|
61
61
|
|
62
|
+
def self.load_rack_app(rack_file)
|
63
|
+
(@rack_app_cache ||= {})[rack_file] ||= Rack::Builder.parse_file(rack_file)
|
64
|
+
end
|
65
|
+
|
66
|
+
#----------------------------------------------------------------------------
|
67
|
+
|
62
68
|
end
|
63
69
|
|
data/lib/rack-rabbit/adapter.rb
CHANGED
@@ -42,7 +42,7 @@ module RackRabbit
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def with_reply_queue(&block)
|
45
|
-
yield
|
45
|
+
yield MockReplyQueue.new :name => "reply.queue"
|
46
46
|
end
|
47
47
|
|
48
48
|
def ack(delivery_tag)
|
@@ -85,6 +85,15 @@ module RackRabbit
|
|
85
85
|
@subscribe_options
|
86
86
|
end
|
87
87
|
|
88
|
+
class MockReplyQueue
|
89
|
+
attr_accessor :name
|
90
|
+
def initialize(options)
|
91
|
+
@name = options[:name]
|
92
|
+
end
|
93
|
+
def delete(*params)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
88
97
|
end
|
89
98
|
|
90
99
|
end
|
data/lib/rack-rabbit/client.rb
CHANGED
@@ -55,6 +55,7 @@ module RackRabbit
|
|
55
55
|
method = options[:method] || :GET
|
56
56
|
headers = options[:headers] || {}
|
57
57
|
response = nil
|
58
|
+
timeout = options[:timeout] || 1
|
58
59
|
|
59
60
|
rabbit.with_reply_queue do |reply_queue|
|
60
61
|
|
@@ -62,6 +63,7 @@ module RackRabbit
|
|
62
63
|
if message.correlation_id == id
|
63
64
|
lock.synchronize do
|
64
65
|
response = Response.new(message.status, message.headers, message.body)
|
66
|
+
reply_queue.delete(if_empty: true)
|
65
67
|
condition.signal
|
66
68
|
end
|
67
69
|
end
|
@@ -84,7 +86,7 @@ module RackRabbit
|
|
84
86
|
end
|
85
87
|
|
86
88
|
lock.synchronize do
|
87
|
-
condition.wait(lock) unless response
|
89
|
+
condition.wait(lock, timeout) unless response
|
88
90
|
end
|
89
91
|
|
90
92
|
response
|
data/lib/rack-rabbit/config.rb
CHANGED
@@ -16,7 +16,7 @@ module RackRabbit
|
|
16
16
|
|
17
17
|
def reload(options = {})
|
18
18
|
@rack_env = nil
|
19
|
-
instance_eval(File.read(config_file), config_file) if config_file && File.
|
19
|
+
instance_eval(File.read(config_file), config_file) if config_file && File.exist?(config_file)
|
20
20
|
validate(options) unless options[:validate] == false
|
21
21
|
end
|
22
22
|
|
@@ -215,9 +215,9 @@ module RackRabbit
|
|
215
215
|
|
216
216
|
raise ArgumentError, "must provide EITHER a :queue OR an :exchange to subscribe to" if queue.nil? && exchange.nil?
|
217
217
|
raise ArgumentError, "missing app_id" if app_id.to_s.empty?
|
218
|
-
raise ArgumentError, "invalid workers" unless workers.is_a?(
|
219
|
-
raise ArgumentError, "invalid min_workers" unless min_workers.is_a?(
|
220
|
-
raise ArgumentError, "invalid max_workers" unless max_workers.is_a?(
|
218
|
+
raise ArgumentError, "invalid workers" unless workers.is_a?(Integer)
|
219
|
+
raise ArgumentError, "invalid min_workers" unless min_workers.is_a?(Integer)
|
220
|
+
raise ArgumentError, "invalid max_workers" unless max_workers.is_a?(Integer)
|
221
221
|
raise ArgumentError, "invalid workers < min_workers" if workers < min_workers
|
222
222
|
raise ArgumentError, "invalid workers > max_workers" if workers > max_workers
|
223
223
|
raise ArgumentError, "invalid min_workers > max_workers" if min_workers > max_workers
|
data/lib/rack-rabbit/message.rb
CHANGED
@@ -25,6 +25,8 @@ module RackRabbit
|
|
25
25
|
@content_encoding = properties.content_encoding
|
26
26
|
@content_length = body.nil? ? 0 : body.length
|
27
27
|
@rabbit = rabbit
|
28
|
+
@acknowledged = nil
|
29
|
+
@rejected = nil
|
28
30
|
end
|
29
31
|
|
30
32
|
#--------------------------------------------------------------------------
|
data/lib/rack-rabbit/server.rb
CHANGED
@@ -248,7 +248,7 @@ module RackRabbit
|
|
248
248
|
#==========================================================================
|
249
249
|
|
250
250
|
def load_app
|
251
|
-
inner_app,
|
251
|
+
inner_app, _options = RackRabbit.load_rack_app(config.rack_file)
|
252
252
|
@app = Rack::Builder.new do
|
253
253
|
use RackRabbit::Middleware::ProgramName
|
254
254
|
run inner_app
|
@@ -31,7 +31,7 @@ module RackRabbit
|
|
31
31
|
:exchange => config.exchange,
|
32
32
|
:exchange_type => config.exchange_type,
|
33
33
|
:routing_key => config.routing_key,
|
34
|
-
:
|
34
|
+
:manual_ack => config.ack) do |message|
|
35
35
|
lock.synchronize do
|
36
36
|
start = Time.now
|
37
37
|
response = handle(message)
|
data/test/test_case.rb
CHANGED
@@ -21,7 +21,7 @@ require 'rack-rabbit/config' # server configuration
|
|
21
21
|
require 'rack-rabbit/signals' # process signal queue
|
22
22
|
|
23
23
|
module RackRabbit
|
24
|
-
class TestCase < Minitest::
|
24
|
+
class TestCase < Minitest::Test
|
25
25
|
|
26
26
|
#--------------------------------------------------------------------------
|
27
27
|
|
@@ -102,7 +102,7 @@ module RackRabbit
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def build_app(rack_file)
|
105
|
-
|
105
|
+
RackRabbit.load_rack_app(rack_file)[0]
|
106
106
|
end
|
107
107
|
|
108
108
|
def build_handler(options = {})
|
@@ -124,6 +124,20 @@ module RackRabbit
|
|
124
124
|
|
125
125
|
#--------------------------------------------------------------------------
|
126
126
|
|
127
|
+
# FUCK MT6 forcing me to use assert_nil when I want to user assert_equal
|
128
|
+
alias_method :orig_assert_equal, :assert_equal
|
129
|
+
def assert_equal(exp, act, msg = nil)
|
130
|
+
if exp.nil?
|
131
|
+
assert_nil act, msg
|
132
|
+
else
|
133
|
+
orig_assert_equal(exp, act, msg)
|
134
|
+
end
|
135
|
+
# msg = message(msg, E) { diff exp, act }
|
136
|
+
# assert exp == act, msg
|
137
|
+
end
|
138
|
+
|
139
|
+
#--------------------------------------------------------------------------
|
140
|
+
|
127
141
|
def assert_raises_argument_error(message = nil, &block)
|
128
142
|
e = assert_raises(ArgumentError, &block)
|
129
143
|
assert_match(/#{message}/, e.message) unless message.nil?
|
data/test/unit/test_config.rb
CHANGED
@@ -200,10 +200,10 @@ module RackRabbit
|
|
200
200
|
|
201
201
|
def test_queue_or_exchange_is_required
|
202
202
|
assert_raises_argument_error("must provide EITHER a :queue OR an :exchange") do
|
203
|
-
|
203
|
+
_bad = build_config(:validate => true)
|
204
204
|
end
|
205
|
-
|
206
|
-
|
205
|
+
_good1 = build_config(:validate => true, :queue => "myqueue")
|
206
|
+
_good2 = build_config(:validate => true, :exchange => "myexchange")
|
207
207
|
end
|
208
208
|
|
209
209
|
#--------------------------------------------------------------------------
|
@@ -26,11 +26,22 @@ module RackRabbit
|
|
26
26
|
#--------------------------------------------------------------------------
|
27
27
|
|
28
28
|
def test_subscribe_options
|
29
|
-
|
30
|
-
|
29
|
+
subscriber = build_subscriber({
|
30
|
+
queue: QUEUE,
|
31
|
+
exchange: EXCHANGE,
|
32
|
+
exchange_type: :fanout,
|
33
|
+
routing_key: ROUTE,
|
34
|
+
ack: true
|
35
|
+
})
|
31
36
|
rabbit = subscriber.rabbit
|
32
37
|
subscriber.subscribe
|
33
|
-
assert_equal(
|
38
|
+
assert_equal({
|
39
|
+
queue: QUEUE,
|
40
|
+
exchange: EXCHANGE,
|
41
|
+
exchange_type: :fanout,
|
42
|
+
routing_key: ROUTE,
|
43
|
+
manual_ack: true
|
44
|
+
}, rabbit.subscribe_options)
|
34
45
|
end
|
35
46
|
|
36
47
|
#--------------------------------------------------------------------------
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-rabbit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jake Gordon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-07-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -83,7 +83,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
83
83
|
version: '0'
|
84
84
|
requirements: []
|
85
85
|
rubyforge_project:
|
86
|
-
rubygems_version: 2.
|
86
|
+
rubygems_version: 2.6.11
|
87
87
|
signing_key:
|
88
88
|
specification_version: 4
|
89
89
|
summary: A Unicorn-style forking, rack-based server for hosting rabbitMQ consumer
|