evrone-common-amqp 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/evrone/common/amqp/config.rb +9 -13
- data/lib/evrone/common/amqp/consumer/publish.rb +2 -2
- data/lib/evrone/common/amqp/consumer/subscribe.rb +3 -3
- data/lib/evrone/common/amqp/consumer.rb +1 -1
- data/lib/evrone/common/amqp/mixins/callbacks.rb +25 -0
- data/lib/evrone/common/amqp/version.rb +1 -1
- data/lib/evrone/common/amqp.rb +1 -1
- data/spec/lib/amqp/config_spec.rb +21 -0
- data/spec/lib/amqp/mixins/callbacks_spec.rb +26 -0
- metadata +7 -5
- data/lib/evrone/common/amqp/mixins/with_middleware.rb +0 -16
- data/spec/lib/amqp/mixins/with_middleware_spec.rb +0 -32
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c24324f4e19411cb06a578695a44e8f495b1a9b8
|
4
|
+
data.tar.gz: e91da1a141c2eb6581e8a7f377186312a6b71488
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: deb6175551f9b6569783539f33ad9c4836bf70db5dded7a1d6d8c2ddf38ab709c78d68e7e1aeb11848d7eec135d378adf07d1b2df3bf877d858aa3f9586b06d2
|
7
|
+
data.tar.gz: 77e583d9cc31af0ada5f625a1e3c51eac418ee3f6569d0ee66f2bddd03a4971fe5b981c02f1f4bc633ea04a29684b7367a61cff01556e76b2b064336cb3f1977
|
@@ -8,9 +8,7 @@ module Evrone
|
|
8
8
|
|
9
9
|
attr_accessor :url, :default_exchange_options, :default_queue_options,
|
10
10
|
:default_publish_options, :default_exchange_type, :logger, :pool_timeout,
|
11
|
-
:heartbeat, :spawn_attempts, :content_type
|
12
|
-
|
13
|
-
attr_reader :publishing_builder, :recieving_builder, :subscribing_builder
|
11
|
+
:heartbeat, :spawn_attempts, :content_type, :callbacks
|
14
12
|
|
15
13
|
def initialize
|
16
14
|
reset!
|
@@ -20,16 +18,12 @@ module Evrone
|
|
20
18
|
Common::AMQP::Formatter
|
21
19
|
end
|
22
20
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
def subscribing(&block)
|
32
|
-
@subscribing_builder = Common::Rack::Builder.new(&block)
|
21
|
+
%w{ before after }.each do |p|
|
22
|
+
%w{ subscribe publish recieve }.each do |m|
|
23
|
+
define_method "#{p}_#{m}" do |&callback|
|
24
|
+
callbacks["#{p}_#{m}".to_sym] = callback
|
25
|
+
end
|
26
|
+
end
|
33
27
|
end
|
34
28
|
|
35
29
|
def default_exchange_name
|
@@ -51,6 +45,8 @@ module Evrone
|
|
51
45
|
|
52
46
|
@content_type = 'application/json'
|
53
47
|
|
48
|
+
@callbacks = {}
|
49
|
+
|
54
50
|
@default_exchange_options = {
|
55
51
|
durable: true,
|
56
52
|
auto_delete: false
|
@@ -13,8 +13,8 @@ module Evrone
|
|
13
13
|
|
14
14
|
x = declare_exchange
|
15
15
|
|
16
|
-
|
17
|
-
m = serialize_message
|
16
|
+
run_callbacks(:publish, message: message, exchange: x) do
|
17
|
+
m = serialize_message message, options[:content_type]
|
18
18
|
x.publish m, options
|
19
19
|
end
|
20
20
|
|
@@ -10,7 +10,7 @@ module Evrone
|
|
10
10
|
x = declare_exchange
|
11
11
|
q = declare_queue
|
12
12
|
|
13
|
-
|
13
|
+
run_callbacks(:subscribe, exchange: x, queue: q) do
|
14
14
|
debug "subscribing to #{q.name}:#{x.name} using #{bind_options.inspect}"
|
15
15
|
q.bind(x, bind_options)
|
16
16
|
debug "successfuly subscribed to #{q.name}:#{x.name}"
|
@@ -47,11 +47,11 @@ module Evrone
|
|
47
47
|
def run_instance(delivery_info, properties, payload)
|
48
48
|
payload = deserialize_message properties, payload
|
49
49
|
|
50
|
-
|
50
|
+
run_callbacks :recieve, payload: payload do
|
51
51
|
new.tap do |inst|
|
52
52
|
inst.properties = properties
|
53
53
|
inst.delivery_info = delivery_info
|
54
|
-
end.perform
|
54
|
+
end.perform payload
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Evrone
|
2
|
+
module Common
|
3
|
+
module AMQP
|
4
|
+
module Callbacks
|
5
|
+
|
6
|
+
def run_callbacks(name, *args)
|
7
|
+
before = "before_#{name}".to_sym
|
8
|
+
after = "after_#{name}".to_sym
|
9
|
+
if f = Common::AMQP.config.callbacks[before]
|
10
|
+
f.call(*args)
|
11
|
+
end
|
12
|
+
|
13
|
+
rs = yield if block_given?
|
14
|
+
|
15
|
+
if f = Common::AMQP.config.callbacks[after]
|
16
|
+
f.call(*args)
|
17
|
+
end
|
18
|
+
|
19
|
+
rs
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/lib/evrone/common/amqp.rb
CHANGED
@@ -15,7 +15,7 @@ module Evrone
|
|
15
15
|
end
|
16
16
|
|
17
17
|
autoload :Logger, File.expand_path("../amqp/mixins/logger", __FILE__)
|
18
|
-
autoload :
|
18
|
+
autoload :Callbacks, File.expand_path("../amqp/mixins/callbacks", __FILE__)
|
19
19
|
|
20
20
|
extend self
|
21
21
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Evrone::Common::AMQP::Config do
|
4
|
+
let(:config) { described_class.new }
|
5
|
+
|
6
|
+
context '(callbacks)' do
|
7
|
+
%w{ before after }.each do |p|
|
8
|
+
%w{ subscribe recieve publish }.each do |m|
|
9
|
+
name = "#{p}_#{m}"
|
10
|
+
it name do
|
11
|
+
config.public_send name do |value|
|
12
|
+
value
|
13
|
+
end
|
14
|
+
|
15
|
+
val = config.callbacks[name.to_sym].call("value")
|
16
|
+
expect(val).to eq 'value'
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Evrone::Common::AMQP::Callbacks do
|
4
|
+
let(:output) { [] }
|
5
|
+
let(:object) { Object.new.extend described_class }
|
6
|
+
|
7
|
+
before do
|
8
|
+
Evrone::Common::AMQP.config.reset!
|
9
|
+
Evrone::Common::AMQP.configure do |c|
|
10
|
+
c.before_publish { |v| output << "before:#{v}" }
|
11
|
+
c.after_publish { |v| output << "after:#{v}" }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
after { Evrone::Common::AMQP.config.reset! }
|
16
|
+
|
17
|
+
context 'run_callbacks' do
|
18
|
+
it "should be success" do
|
19
|
+
object.run_callbacks :publish, "call" do
|
20
|
+
output << "call"
|
21
|
+
end
|
22
|
+
expect(output).to eq %w{ before:call call after:call }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: evrone-common-amqp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Galinsky
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bunny
|
@@ -120,17 +120,18 @@ files:
|
|
120
120
|
- lib/evrone/common/amqp/consumer/publish.rb
|
121
121
|
- lib/evrone/common/amqp/consumer/subscribe.rb
|
122
122
|
- lib/evrone/common/amqp/formatter.rb
|
123
|
+
- lib/evrone/common/amqp/mixins/callbacks.rb
|
123
124
|
- lib/evrone/common/amqp/mixins/logger.rb
|
124
|
-
- lib/evrone/common/amqp/mixins/with_middleware.rb
|
125
125
|
- lib/evrone/common/amqp/session.rb
|
126
126
|
- lib/evrone/common/amqp/supervisor/threaded.rb
|
127
127
|
- lib/evrone/common/amqp/testing.rb
|
128
128
|
- lib/evrone/common/amqp/version.rb
|
129
129
|
- spec/integration/multi_threaded_spec.rb
|
130
130
|
- spec/integration/threaded_supervisor_spec.rb
|
131
|
+
- spec/lib/amqp/config_spec.rb
|
131
132
|
- spec/lib/amqp/consumer_spec.rb
|
132
133
|
- spec/lib/amqp/formatter_spec.rb
|
133
|
-
- spec/lib/amqp/mixins/
|
134
|
+
- spec/lib/amqp/mixins/callbacks_spec.rb
|
134
135
|
- spec/lib/amqp/session_spec.rb
|
135
136
|
- spec/lib/amqp/supervisor/threaded_spec.rb
|
136
137
|
- spec/lib/amqp_spec.rb
|
@@ -164,9 +165,10 @@ summary: Common amqp code
|
|
164
165
|
test_files:
|
165
166
|
- spec/integration/multi_threaded_spec.rb
|
166
167
|
- spec/integration/threaded_supervisor_spec.rb
|
168
|
+
- spec/lib/amqp/config_spec.rb
|
167
169
|
- spec/lib/amqp/consumer_spec.rb
|
168
170
|
- spec/lib/amqp/formatter_spec.rb
|
169
|
-
- spec/lib/amqp/mixins/
|
171
|
+
- spec/lib/amqp/mixins/callbacks_spec.rb
|
170
172
|
- spec/lib/amqp/session_spec.rb
|
171
173
|
- spec/lib/amqp/supervisor/threaded_spec.rb
|
172
174
|
- spec/lib/amqp_spec.rb
|
@@ -1,16 +0,0 @@
|
|
1
|
-
module Evrone
|
2
|
-
module Common
|
3
|
-
module AMQP
|
4
|
-
module WithMiddleware
|
5
|
-
def with_middleware(name, env, &block)
|
6
|
-
builder = Common::AMQP.config.public_send("#{name}_builder")
|
7
|
-
if builder
|
8
|
-
builder.to_app(block).call env
|
9
|
-
else
|
10
|
-
yield env
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
@@ -1,32 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Evrone::Common::AMQP::WithMiddleware do
|
4
|
-
let(:object) { Object.new.extend described_class }
|
5
|
-
|
6
|
-
Foo = Struct.new(:app, :id) do
|
7
|
-
def call(env)
|
8
|
-
env << "called"
|
9
|
-
app.call env
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
before { Evrone::Common::AMQP.config.reset! }
|
14
|
-
after { Evrone::Common::AMQP.config.reset! }
|
15
|
-
|
16
|
-
context 'with_middleware' do
|
17
|
-
it "should be successfull" do
|
18
|
-
Evrone::Common::AMQP.configure do |c|
|
19
|
-
c.publishing do
|
20
|
-
use Foo, :id
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
collected = ""
|
25
|
-
object.with_middleware(:publishing, "") do |env|
|
26
|
-
collected << env
|
27
|
-
end
|
28
|
-
expect(collected).to eq 'called'
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|