mercury_amqp 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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1e3452ba7fb74955df9eb81a1481fd48f7d7a060
|
4
|
+
data.tar.gz: 8e119f5f19189c9cee7095bb39990ce99c8575a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd514973a3c22508ca2f1f1d92799fdfc638fd4f64fd9d06d21b260b633b4ec793858394762fdc14be96afbd3ab306d9e0cdf016d80d94e19364b99c30f1d7c4
|
7
|
+
data.tar.gz: 62df2a2d2c51ca01be73aa439d45869ee82b38b63685c82757f9c6219069b11bf677fe2ad60b3ab52f44f8324185579b995049509b956040c4989af906bd4efc
|
@@ -9,7 +9,7 @@ class Mercury
|
|
9
9
|
|
10
10
|
def initialize(queue, msg, tag, headers, is_ackable)
|
11
11
|
metadata = Metadata.new(tag, headers, proc{queue.ack_or_reject_message(self)}, proc{queue.nack(self)})
|
12
|
-
@received_msg = ReceivedMessage.new(msg, metadata, work_queue_name: is_ackable ? queue.worker : nil)
|
12
|
+
@received_msg = ReceivedMessage.new(msg, metadata, nil, work_queue_name: is_ackable ? queue.worker : nil)
|
13
13
|
@headers = headers
|
14
14
|
@delivered = false
|
15
15
|
end
|
data/lib/mercury/mercury.rb
CHANGED
@@ -72,6 +72,8 @@ class Mercury
|
|
72
72
|
def republish(msg, &k)
|
73
73
|
guard_public(k)
|
74
74
|
raise 'Only messages from a work queue can be republished' unless msg.work_queue_name
|
75
|
+
raise 'A message can only be republished by the mercury instance that received it' unless msg.mercury_instance == self
|
76
|
+
raise "This message was already #{msg.action_taken}ed" if msg.action_taken
|
75
77
|
headers = Mercury.increment_republish_count(msg).merge(ORIGINAL_TAG_HEADER => msg.tag)
|
76
78
|
publish_internal(@channel.default_exchange, msg.content, msg.work_queue_name, headers) do
|
77
79
|
msg.ack
|
@@ -212,7 +214,7 @@ class Mercury
|
|
212
214
|
end
|
213
215
|
|
214
216
|
def make_received_message(payload, metadata, work_queue_name: nil)
|
215
|
-
msg = ReceivedMessage.new(read(payload), metadata, work_queue_name: work_queue_name)
|
217
|
+
msg = ReceivedMessage.new(read(payload), metadata, self, work_queue_name: work_queue_name)
|
216
218
|
Logatron.msg_id = msg.headers[LOGATRAON_MSG_ID_HEADER]
|
217
219
|
msg
|
218
220
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
class Mercury
|
2
2
|
class ReceivedMessage
|
3
|
-
attr_reader :content, :metadata, :action_taken, :work_queue_name
|
3
|
+
attr_reader :content, :metadata, :mercury_instance, :action_taken, :work_queue_name
|
4
4
|
|
5
|
-
def initialize(content, metadata, work_queue_name: nil)
|
5
|
+
def initialize(content, metadata, mercury_instance, work_queue_name: nil)
|
6
6
|
@content = content
|
7
7
|
@metadata = metadata
|
8
|
+
@mercury_instance = mercury_instance
|
8
9
|
@work_queue_name = work_queue_name
|
9
10
|
end
|
10
11
|
|
@@ -35,6 +36,11 @@ class Mercury
|
|
35
36
|
metadata.reject(requeue: true)
|
36
37
|
end
|
37
38
|
|
39
|
+
def republish(&k)
|
40
|
+
k ||= proc{}
|
41
|
+
mercury_instance.republish(self, &k)
|
42
|
+
end
|
43
|
+
|
38
44
|
private
|
39
45
|
|
40
46
|
def is_ackable
|
data/lib/mercury/version.rb
CHANGED
@@ -149,6 +149,21 @@ describe Mercury::Monadic do
|
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
|
+
it 'cannot republish acked messages' do
|
153
|
+
test_with_mercury do |m|
|
154
|
+
msgs = []
|
155
|
+
seql do
|
156
|
+
and_then { m.start_worker(worker, source, &msgs.method(:push)) }
|
157
|
+
and_then { m.publish(source, msg, tag: 'foo', headers: {bar: 123}) }
|
158
|
+
and_then { wait_until { msgs.size == 1 } }
|
159
|
+
and_lift do
|
160
|
+
msgs[0].ack
|
161
|
+
expect{msgs[0].republish}.to raise_error /acked/
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
152
167
|
it 'propagates logatron headers' do
|
153
168
|
real_msg_id = SecureRandom.uuid
|
154
169
|
Logatron.msg_id = real_msg_id
|
@@ -36,6 +36,19 @@ describe Mercury::ReceivedMessage do
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
describe '#republish' do
|
40
|
+
it 'calls Mercury#republish' do
|
41
|
+
mercury_instance = double
|
42
|
+
msg = Mercury::ReceivedMessage.new('hello', make_metadata, mercury_instance, work_queue_name: 'foo')
|
43
|
+
cont = proc{}
|
44
|
+
expect(mercury_instance).to receive(:republish) do |m, &k|
|
45
|
+
expect(m).to eql msg
|
46
|
+
expect(k).to eql cont
|
47
|
+
end
|
48
|
+
msg.republish(&cont)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
39
52
|
describe '#action_taken' do
|
40
53
|
it 'returns the action taken' do
|
41
54
|
a = make_actionable
|
@@ -56,11 +69,11 @@ describe Mercury::ReceivedMessage do
|
|
56
69
|
end
|
57
70
|
|
58
71
|
def make_actionable
|
59
|
-
Mercury::ReceivedMessage.new('hello', make_metadata, work_queue_name: 'foo')
|
72
|
+
Mercury::ReceivedMessage.new('hello', make_metadata, double, work_queue_name: 'foo')
|
60
73
|
end
|
61
74
|
|
62
75
|
def make_non_actionable
|
63
|
-
Mercury::ReceivedMessage.new('hello', make_metadata, work_queue_name: nil)
|
76
|
+
Mercury::ReceivedMessage.new('hello', make_metadata, double, work_queue_name: nil)
|
64
77
|
end
|
65
78
|
|
66
79
|
def make_metadata
|
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.6.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: 2016-05-
|
11
|
+
date: 2016-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|