mercury_amqp 0.1.0 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/mercury/fake.rb +2 -2
- data/lib/mercury/fake/metadata.rb +4 -1
- data/lib/mercury/fake/queue.rb +2 -2
- data/lib/mercury/fake/queued_message.rb +4 -3
- data/lib/mercury/mercury.rb +9 -7
- data/lib/mercury/received_message.rb +4 -0
- data/lib/mercury/sync.rb +1 -1
- data/lib/mercury/version.rb +1 -1
- data/mercury_amqp.gemspec +5 -4
- data/spec/lib/mercury/monadic_spec.rb +34 -0
- metadata +28 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c36195df1d069fa7a74656af985d056b77a609cb
|
4
|
+
data.tar.gz: 4800de94a1d94f443d769b26e335b1257595e9f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89fd0f3e3a2821c4666e885a1c6b5ccfb9e0925620eb0bb657bad0f105a2c0d736896e0995f6dbfcbabec58dc71cf77b4ae559fe423b9eb2c631f4364584d4d1
|
7
|
+
data.tar.gz: fc2643c2a50e24fc33db009b6fd3398018eecc4dea839f375dc58a03fea5ac8b49292e0aec7f41f294d9fa566bad8e855ac0f34e39e45eac5ac6d1f4c5868fb5
|
data/.gitignore
CHANGED
data/lib/mercury/fake.rb
CHANGED
@@ -28,9 +28,9 @@ class Mercury
|
|
28
28
|
ret(k)
|
29
29
|
end
|
30
30
|
|
31
|
-
def publish(source_name, msg, tag: '', &k)
|
31
|
+
def publish(source_name, msg, tag: '', headers: {}, &k)
|
32
32
|
assert_not_closed
|
33
|
-
queues.values.select{|q| q.binds?(source_name, tag)}.each{|q| q.enqueue(roundtrip(msg), tag)}
|
33
|
+
queues.values.select{|q| q.binds?(source_name, tag)}.each{|q| q.enqueue(roundtrip(msg), tag, headers)}
|
34
34
|
ret(k)
|
35
35
|
end
|
36
36
|
|
@@ -1,10 +1,13 @@
|
|
1
1
|
class Mercury
|
2
2
|
class Fake
|
3
3
|
class Metadata
|
4
|
-
|
4
|
+
attr_reader :headers
|
5
|
+
|
6
|
+
def initialize(tag, headers, dequeue, requeue)
|
5
7
|
@tag = tag
|
6
8
|
@dequeue = dequeue
|
7
9
|
@requeue = requeue
|
10
|
+
@headers = headers
|
8
11
|
end
|
9
12
|
|
10
13
|
def routing_key
|
data/lib/mercury/fake/queue.rb
CHANGED
@@ -20,8 +20,8 @@ class Mercury
|
|
20
20
|
deliver # new subscriber probably wants a message
|
21
21
|
end
|
22
22
|
|
23
|
-
def enqueue(msg, tag)
|
24
|
-
msgs.push(QueuedMessage.new(self, msg, tag, @require_ack))
|
23
|
+
def enqueue(msg, tag, headers)
|
24
|
+
msgs.push(QueuedMessage.new(self, msg, tag, headers, @require_ack))
|
25
25
|
deliver # new message. someone probably wants it.
|
26
26
|
end
|
27
27
|
|
@@ -4,12 +4,13 @@ require 'mercury/received_message'
|
|
4
4
|
class Mercury
|
5
5
|
class Fake
|
6
6
|
class QueuedMessage
|
7
|
-
attr_reader :received_msg
|
7
|
+
attr_reader :received_msg, :headers
|
8
8
|
attr_accessor :delivered, :subscriber
|
9
9
|
|
10
|
-
def initialize(queue, msg, tag, is_ackable)
|
11
|
-
metadata = Metadata.new(tag, proc{queue.ack_or_reject_message(self)}, proc{queue.nack(self)})
|
10
|
+
def initialize(queue, msg, tag, headers, is_ackable)
|
11
|
+
metadata = Metadata.new(tag, headers, proc{queue.ack_or_reject_message(self)}, proc{queue.nack(self)})
|
12
12
|
@received_msg = ReceivedMessage.new(msg, metadata, is_ackable: is_ackable)
|
13
|
+
@headers = headers
|
13
14
|
@delivered = false
|
14
15
|
end
|
15
16
|
end
|
data/lib/mercury/mercury.rb
CHANGED
@@ -2,12 +2,12 @@ require 'amqp'
|
|
2
2
|
require 'securerandom'
|
3
3
|
require 'mercury/wire_serializer'
|
4
4
|
require 'mercury/received_message'
|
5
|
-
require '
|
5
|
+
require 'logatron/logatron'
|
6
6
|
|
7
7
|
class Mercury
|
8
8
|
attr_reader :amqp, :channel, :logger
|
9
9
|
|
10
|
-
def self.open(logger:
|
10
|
+
def self.open(logger: Logatron, **kws, &k)
|
11
11
|
@logger = logger
|
12
12
|
new(**kws, &k)
|
13
13
|
nil
|
@@ -36,19 +36,19 @@ class Mercury
|
|
36
36
|
end
|
37
37
|
private_class_method :new
|
38
38
|
|
39
|
-
def publish(source_name, msg, tag: '', &k)
|
39
|
+
def publish(source_name, msg, tag: '', headers: {}, &k)
|
40
40
|
# The amqp gem caches exchange objects, so it's fine to
|
41
41
|
# redeclare the exchange every time we publish.
|
42
42
|
# TODO: wait for publish confirmations (@channel.on_ack)
|
43
43
|
with_source(source_name) do |exchange|
|
44
|
-
exchange.publish(write(msg), **Mercury.publish_opts(tag)) do
|
44
|
+
exchange.publish(write(msg), **Mercury.publish_opts(tag, headers)) do
|
45
45
|
k.call
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
-
def self.publish_opts(tag)
|
51
|
-
{ routing_key: tag, persistent: true }
|
50
|
+
def self.publish_opts(tag, headers)
|
51
|
+
{ routing_key: tag, persistent: true, headers: Logatron.http_headers.merge(headers) }
|
52
52
|
end
|
53
53
|
|
54
54
|
def start_listener(source_name, handler, tag_filter: '#', &k)
|
@@ -108,7 +108,9 @@ class Mercury
|
|
108
108
|
private
|
109
109
|
|
110
110
|
def make_received_message(payload, metadata, is_ackable)
|
111
|
-
ReceivedMessage.new(read(payload), metadata, is_ackable: is_ackable)
|
111
|
+
msg = ReceivedMessage.new(read(payload), metadata, is_ackable: is_ackable)
|
112
|
+
Logatron.msg_id = msg.headers['X-Ascent-Log-Id']
|
113
|
+
msg
|
112
114
|
end
|
113
115
|
|
114
116
|
def existence_check(k, &check)
|
data/lib/mercury/sync.rb
CHANGED
@@ -10,7 +10,7 @@ class Mercury
|
|
10
10
|
ch = conn.create_channel
|
11
11
|
ch.confirm_select
|
12
12
|
ex = ch.topic(source_name, Mercury.source_opts)
|
13
|
-
ex.publish(WireSerializer.new.write(msg), **Mercury.publish_opts(tag))
|
13
|
+
ex.publish(WireSerializer.new.write(msg), **Mercury.publish_opts(tag, {}))
|
14
14
|
ch.wait_for_confirms or raise 'failed to confirm publication'
|
15
15
|
ensure
|
16
16
|
conn.close
|
data/lib/mercury/version.rb
CHANGED
data/mercury_amqp.gemspec
CHANGED
@@ -20,14 +20,15 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
22
|
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
-
spec.add_development_dependency 'yard'
|
23
|
+
spec.add_development_dependency 'yard', '~> 0'
|
24
24
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
-
spec.add_development_dependency 'json_spec'
|
26
|
-
spec.add_development_dependency 'evented-spec'
|
27
|
-
spec.add_development_dependency 'rspec_junit_formatter'
|
25
|
+
spec.add_development_dependency 'json_spec', '~> 1'
|
26
|
+
spec.add_development_dependency 'evented-spec', '~> 0.9'
|
27
|
+
spec.add_development_dependency 'rspec_junit_formatter', '~> 0'
|
28
28
|
|
29
29
|
spec.add_runtime_dependency 'oj', '~> 2.12'
|
30
30
|
spec.add_runtime_dependency 'amqp', '~> 1.5'
|
31
31
|
spec.add_runtime_dependency 'bunny', '~> 2.1'
|
32
32
|
spec.add_runtime_dependency 'binding_of_caller', '~> 0.7'
|
33
|
+
spec.add_runtime_dependency 'logatron', '~> 0'
|
33
34
|
end
|
@@ -2,6 +2,8 @@ require 'rspec'
|
|
2
2
|
require 'spec_helper'
|
3
3
|
require 'mercury'
|
4
4
|
require 'mercury/monadic'
|
5
|
+
require 'securerandom'
|
6
|
+
require 'logatron/logatron'
|
5
7
|
|
6
8
|
describe Mercury::Monadic do
|
7
9
|
include Cps::Methods
|
@@ -65,6 +67,38 @@ describe Mercury::Monadic do
|
|
65
67
|
end
|
66
68
|
end
|
67
69
|
|
70
|
+
itt 'sends and receives headers' do
|
71
|
+
test_with_mercury do |m|
|
72
|
+
msgs = []
|
73
|
+
seql do
|
74
|
+
and_then { m.start_listener(source, &msgs.method(:push)) }
|
75
|
+
and_then { m.publish(source, msg, headers: {'foo' => 'bar'}) }
|
76
|
+
and_then { wait_until { msgs.size == 1 } }
|
77
|
+
and_lift do
|
78
|
+
expect(msgs[0].headers['foo']).to eql 'bar'
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'propagates logatron headers' do
|
85
|
+
real_msg_id = SecureRandom.uuid
|
86
|
+
Logatron.msg_id = real_msg_id
|
87
|
+
test_with_mercury do |m|
|
88
|
+
msgs = []
|
89
|
+
seql do
|
90
|
+
and_then { m.start_listener(source, &msgs.method(:push)) }
|
91
|
+
and_then { m.publish(source, msg) }
|
92
|
+
and_lift { Logatron.msg_id = 'fake_msg_id' }
|
93
|
+
and_then { wait_until { msgs.size == 1 } }
|
94
|
+
and_lift do
|
95
|
+
expect(msgs[0].headers['X-Ascent-Log-Id']).to eql real_msg_id
|
96
|
+
expect(Logatron.msg_id).to eql real_msg_id
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
68
102
|
itt 'uses AMQP-style tag filters' do
|
69
103
|
test_with_mercury do |m|
|
70
104
|
successes = []
|
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.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Winton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -42,14 +42,14 @@ dependencies:
|
|
42
42
|
name: yard
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
@@ -70,42 +70,42 @@ dependencies:
|
|
70
70
|
name: json_spec
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: '
|
75
|
+
version: '1'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: '
|
82
|
+
version: '1'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: evented-spec
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '0'
|
89
|
+
version: '0.9'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '0'
|
96
|
+
version: '0.9'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: rspec_junit_formatter
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
@@ -164,6 +164,20 @@ 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'
|
167
181
|
description: Abstracts common patterns used with AMQP
|
168
182
|
email:
|
169
183
|
- wintonpc@gmail.com
|