mercury_amqp 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -11
- data/lib/mercury/mercury.rb +5 -8
- data/lib/mercury/sync.rb +2 -2
- data/mercury_amqp.gemspec +1 -2
- data/spec/lib/mercury/cps_spec.rb +0 -2
- data/spec/lib/mercury/mercury_spec.rb +5 -3
- data/spec/lib/mercury/monadic_spec.rb +0 -19
- data/spec/lib/mercury/sync_spec.rb +3 -1
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 141403cd276f3d2a983a66c0cafbf79ba4c2326f
|
4
|
+
data.tar.gz: 89911705adad454ece304fce82bfb8135d172d4e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce0b2c4e559f687a749d9484634c88e85f777aa52fa21dbd69519e91e0c1537e388c9927a14ab9cef14f906e8480bc614a5003b6f45ce159ddb9dae80c3d544f
|
7
|
+
data.tar.gz: 1e2be3340a8bfa0ee9db21adccbad1997532f357472d71da08af205020d100d090ca10dd2765549fd715132fd2b34785314ac46517a069315a0b2a5381eef041
|
data/README.md
CHANGED
@@ -105,15 +105,6 @@ arbitrary encoding. The receiving client receives the exact same
|
|
105
105
|
string as the message content (assuming the serialized message fails to
|
106
106
|
parse as JSON).
|
107
107
|
|
108
|
-
### Logatron integration
|
109
|
-
|
110
|
-
Mercury depends on the
|
111
|
-
[`logatron`][logatron] gem and propagates
|
112
|
-
logatron's request ID (`Logatron.msg_id`) through the AMQP header
|
113
|
-
`X-Ascent-Log-Id`. This enables a log aggregation service to find the
|
114
|
-
logs associated with a particular incoming request, even though the
|
115
|
-
log entries may be scattered across various services.
|
116
|
-
|
117
108
|
### Thread safety
|
118
109
|
|
119
110
|
Mercury is not threadsafe. All calls to a particular instance must be made from the
|
@@ -423,7 +414,6 @@ is being intentionally ignored.
|
|
423
414
|
|
424
415
|
[amqp]: https://github.com/ruby-amqp/amqp
|
425
416
|
[em]: https://github.com/eventmachine/eventmachine
|
426
|
-
[logatron]: https://github.com/indigobio/logatron
|
427
417
|
[em_defer]: http://www.rubydoc.info/github/eventmachine/eventmachine/EventMachine.defer
|
428
418
|
[fiber_defer]: https://github.com/indigobio/abstractivator/blob/master/lib/abstractivator/fiber_defer.rb
|
429
|
-
[default_exchange]: https://www.rabbitmq.com/tutorials/amqp-concepts.html
|
419
|
+
[default_exchange]: https://www.rabbitmq.com/tutorials/amqp-concepts.html
|
data/lib/mercury/mercury.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'amqp'
|
2
2
|
require 'securerandom'
|
3
|
+
require 'logger'
|
3
4
|
require 'mercury/wire_serializer'
|
4
5
|
require 'mercury/received_message'
|
5
|
-
require '
|
6
|
+
require 'active_support/core_ext/enumerable'
|
6
7
|
|
7
8
|
class Mercury
|
8
9
|
ORIGINAL_TAG_HEADER = 'Original-Tag'.freeze
|
@@ -10,7 +11,7 @@ class Mercury
|
|
10
11
|
|
11
12
|
attr_reader :amqp, :channel, :logger
|
12
13
|
|
13
|
-
def self.open(logger:
|
14
|
+
def self.open(logger: Logger.new(STDOUT), **kws, &k)
|
14
15
|
new(logger: logger, **kws, &k)
|
15
16
|
nil
|
16
17
|
end
|
@@ -94,7 +95,7 @@ class Mercury
|
|
94
95
|
private :publish_internal
|
95
96
|
|
96
97
|
def self.publish_opts(tag, headers)
|
97
|
-
{ routing_key: tag, persistent: true, headers:
|
98
|
+
{ routing_key: tag, persistent: true, headers: headers }
|
98
99
|
end
|
99
100
|
|
100
101
|
def start_listener(source_name, handler, tag_filter: nil, &k)
|
@@ -159,8 +160,6 @@ class Mercury
|
|
159
160
|
|
160
161
|
private
|
161
162
|
|
162
|
-
LOGATRAON_MSG_ID_HEADER = 'X-Ascent-Log-Id'.freeze
|
163
|
-
|
164
163
|
# In AMQP, queue consumers ack requests after handling them. Unacked messages
|
165
164
|
# are automatically returned to the queue, guaranteeing they are eventually handled.
|
166
165
|
# Services often ack one request while publishing related messages. Ideally, these
|
@@ -214,9 +213,7 @@ class Mercury
|
|
214
213
|
end
|
215
214
|
|
216
215
|
def make_received_message(payload, metadata, work_queue_name: nil)
|
217
|
-
|
218
|
-
Logatron.msg_id = msg.headers[LOGATRAON_MSG_ID_HEADER]
|
219
|
-
msg
|
216
|
+
ReceivedMessage.new(read(payload), metadata, self, work_queue_name: work_queue_name)
|
220
217
|
end
|
221
218
|
|
222
219
|
def existence_check(k, &check)
|
data/lib/mercury/sync.rb
CHANGED
@@ -4,14 +4,14 @@ require 'bunny'
|
|
4
4
|
class Mercury
|
5
5
|
class Sync
|
6
6
|
class << self
|
7
|
-
def publish(source_name, msg, tag: '', amqp_opts: {}, wait_for_publisher_confirms: true)
|
7
|
+
def publish(source_name, msg, tag: '', headers: {}, amqp_opts: {}, wait_for_publisher_confirms: true)
|
8
8
|
conn = Bunny.new(amqp_opts)
|
9
9
|
conn.start
|
10
10
|
ch = conn.create_channel
|
11
11
|
|
12
12
|
ch.confirm_select if wait_for_publisher_confirms # see http://rubybunny.info/articles/extensions.html and Mercury#enable_publisher_confirms
|
13
13
|
ex = ch.topic(source_name, Mercury.source_opts)
|
14
|
-
ex.publish(WireSerializer.new.write(msg), **Mercury.publish_opts(tag,
|
14
|
+
ex.publish(WireSerializer.new.write(msg), **Mercury.publish_opts(tag, headers))
|
15
15
|
if wait_for_publisher_confirms
|
16
16
|
ch.wait_for_confirms or raise 'failed to confirm publication'
|
17
17
|
end
|
data/mercury_amqp.gemspec
CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'mercury_amqp'
|
7
|
-
spec.version = '0.
|
7
|
+
spec.version = '0.8.0'
|
8
8
|
spec.authors = ['Peter Winton']
|
9
9
|
spec.email = ['wintonpc@gmail.com']
|
10
10
|
spec.summary = 'AMQP-backed messaging layer'
|
@@ -29,6 +29,5 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.add_runtime_dependency 'amqp', '~> 1.5'
|
30
30
|
spec.add_runtime_dependency 'bunny', '~> 2.1'
|
31
31
|
spec.add_runtime_dependency 'binding_of_caller', '~> 0.7'
|
32
|
-
spec.add_runtime_dependency 'logatron', '~> 0'
|
33
32
|
spec.add_runtime_dependency 'activesupport', '> 4.0', '< 6.0'
|
34
33
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
require 'mercury'
|
3
|
+
require 'logger'
|
3
4
|
|
4
5
|
describe Mercury do
|
5
6
|
include MercuryFakeSpec
|
@@ -10,6 +11,7 @@ describe Mercury do
|
|
10
11
|
let!(:sent) { { 'a' => 1 } }
|
11
12
|
let!(:source) { 'test-exchange' }
|
12
13
|
let!(:queue) { 'test-queue' }
|
14
|
+
let(:nullogger) { Logger.new(File::NULL) }
|
13
15
|
|
14
16
|
describe '::open' do
|
15
17
|
it 'opens a mercury instance' do
|
@@ -82,7 +84,7 @@ describe Mercury do
|
|
82
84
|
# end
|
83
85
|
|
84
86
|
it 'raises an error when the connection breaks' do
|
85
|
-
expect { em { Mercury.open { done } } }.to raise_error /Lost connection/
|
87
|
+
expect { em { Mercury.open(logger: nullogger) { done } } }.to raise_error /Lost connection/
|
86
88
|
expect(EM.reactor_running?).to be false # make sure we're not triggering EventMachine cleanup bugs
|
87
89
|
end
|
88
90
|
|
@@ -137,7 +139,7 @@ describe Mercury do
|
|
137
139
|
it 'raises when an error occurs' do
|
138
140
|
expect do
|
139
141
|
em do
|
140
|
-
Mercury.open do |m|
|
142
|
+
Mercury.open(logger: nullogger) do |m|
|
141
143
|
ch = m.instance_variable_get(:@channel)
|
142
144
|
ch.acknowledge(42) # force a channel error
|
143
145
|
end
|
@@ -153,7 +155,7 @@ describe Mercury do
|
|
153
155
|
@mercury.publish(source, 'hello')
|
154
156
|
end
|
155
157
|
end
|
156
|
-
Mercury.open(on_error: handler) do |m|
|
158
|
+
Mercury.open(logger: nullogger, on_error: handler) do |m|
|
157
159
|
@mercury = m
|
158
160
|
ch = m.instance_variable_get(:@channel)
|
159
161
|
ch.acknowledge(42) # force a channel error
|
@@ -3,7 +3,6 @@ require 'spec_helper'
|
|
3
3
|
require 'mercury'
|
4
4
|
require 'mercury/monadic'
|
5
5
|
require 'securerandom'
|
6
|
-
require 'logatron/logatron'
|
7
6
|
|
8
7
|
describe Mercury::Monadic do
|
9
8
|
include Cps::Methods
|
@@ -164,24 +163,6 @@ describe Mercury::Monadic do
|
|
164
163
|
end
|
165
164
|
end
|
166
165
|
|
167
|
-
it 'propagates logatron headers' do
|
168
|
-
real_msg_id = SecureRandom.uuid
|
169
|
-
Logatron.msg_id = real_msg_id
|
170
|
-
test_with_mercury do |m|
|
171
|
-
msgs = []
|
172
|
-
seql do
|
173
|
-
and_then { m.start_listener(source, &msgs.method(:push)) }
|
174
|
-
and_lift { EM.next_tick { Logatron.msg_id = 'fake_msg_id' } } # we want this to happen right after publishing but before getting the response
|
175
|
-
and_then { m.publish(source, msg) }
|
176
|
-
and_then { wait_until { msgs.size == 1 } }
|
177
|
-
and_lift do
|
178
|
-
expect(msgs[0].headers['X-Ascent-Log-Id']).to eql real_msg_id
|
179
|
-
expect(Logatron.msg_id).to eql real_msg_id
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
166
|
itt 'uses AMQP-style tag filters' do
|
186
167
|
test_with_mercury do |m|
|
187
168
|
successes = []
|
@@ -6,6 +6,7 @@ describe Mercury::Sync do
|
|
6
6
|
include Cps::Methods
|
7
7
|
let!(:source) { 'test-exchange1' }
|
8
8
|
let!(:queue) { 'test-queue1' }
|
9
|
+
let(:headers) { {'X-Domain-Variable' => 'value'} }
|
9
10
|
describe '::publish' do
|
10
11
|
%w{with without}.each do |w|
|
11
12
|
it "publishes synchronously (#{w} publisher confirms)" do
|
@@ -15,11 +16,12 @@ describe Mercury::Sync do
|
|
15
16
|
test_with_mercury(wait_for_publisher_confirms: use_publisher_confirms) do |m|
|
16
17
|
seql do
|
17
18
|
and_then { m.start_listener(source, received.method(:push)) }
|
18
|
-
and_lift { Mercury::Sync.publish(source, sent) }
|
19
|
+
and_lift { Mercury::Sync.publish(source, sent, headers: headers) }
|
19
20
|
and_then { wait_until { received.any? } }
|
20
21
|
and_lift do
|
21
22
|
expect(received.size).to eql 1
|
22
23
|
expect(received[0].content).to eql sent
|
24
|
+
expect(received[0].headers).to eql headers
|
23
25
|
end
|
24
26
|
end
|
25
27
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mercury_amqp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Winton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -164,20 +164,6 @@ dependencies:
|
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '0.7'
|
167
|
-
- !ruby/object:Gem::Dependency
|
168
|
-
name: logatron
|
169
|
-
requirement: !ruby/object:Gem::Requirement
|
170
|
-
requirements:
|
171
|
-
- - "~>"
|
172
|
-
- !ruby/object:Gem::Version
|
173
|
-
version: '0'
|
174
|
-
type: :runtime
|
175
|
-
prerelease: false
|
176
|
-
version_requirements: !ruby/object:Gem::Requirement
|
177
|
-
requirements:
|
178
|
-
- - "~>"
|
179
|
-
- !ruby/object:Gem::Version
|
180
|
-
version: '0'
|
181
167
|
- !ruby/object:Gem::Dependency
|
182
168
|
name: activesupport
|
183
169
|
requirement: !ruby/object:Gem::Requirement
|