emque-producing 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -133,7 +133,7 @@ module Emque
|
|
133
133
|
log "valid...", true
|
134
134
|
if Emque::Producing.configuration.publish_messages
|
135
135
|
message = process_middleware(to_json)
|
136
|
-
sent = publisher.publish(topic, message_type, message, partition_key)
|
136
|
+
sent = publisher.publish(topic, message_type, message, partition_key, raise_on_failure?)
|
137
137
|
log "sent #{sent}"
|
138
138
|
raise MessagesNotSentError.new unless sent
|
139
139
|
end
|
@@ -13,22 +13,19 @@ module Emque
|
|
13
13
|
.new(Emque::Producing.configuration.rabbitmq_options[:url])
|
14
14
|
.tap { |conn| conn.start }
|
15
15
|
|
16
|
+
CONFIRM_CHANNEL_POOL = Queue.new.tap {
|
17
|
+
|queue| queue << CONN.create_channel
|
18
|
+
}
|
16
19
|
CHANNEL_POOL = Queue.new.tap { |queue| queue << CONN.create_channel }
|
17
20
|
|
18
|
-
def publish(topic, message_type, message, key = nil)
|
19
|
-
|
20
|
-
ch = CHANNEL_POOL.pop(true)
|
21
|
-
rescue ThreadError
|
22
|
-
ch = CONN.create_channel
|
23
|
-
end
|
21
|
+
def publish(topic, message_type, message, key = nil, raise_on_failure)
|
22
|
+
ch = get_channel(raise_on_failure)
|
24
23
|
|
25
24
|
ch.open if ch.closed?
|
26
25
|
begin
|
27
26
|
exchange = ch.fanout(topic, :durable => true, :auto_delete => false)
|
28
27
|
|
29
|
-
|
30
|
-
# the message was not sent. Uses publisher confirms to wait.
|
31
|
-
ch.confirm_select
|
28
|
+
ch.confirm_select if raise_on_failure
|
32
29
|
sent = true
|
33
30
|
|
34
31
|
exchange.on_return do |return_info, properties, content|
|
@@ -42,19 +39,38 @@ module Emque
|
|
42
39
|
:persistent => true,
|
43
40
|
:type => message_type,
|
44
41
|
:app_id => Emque::Producing.configuration.app_name,
|
45
|
-
:content_type => "application/json"
|
42
|
+
:content_type => "application/json"
|
43
|
+
)
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
45
|
+
if raise_on_failure
|
46
|
+
success = ch.wait_for_confirms
|
47
|
+
unless success
|
48
|
+
Emque::Producing.logger.warn("RabbitMQ Publisher: message was nacked")
|
49
|
+
ch.nacked_set.each do |n|
|
50
|
+
Emque::Producing.logger.warn("message id: #{n}")
|
51
|
+
end
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
return sent
|
56
56
|
ensure
|
57
|
-
|
57
|
+
if raise_on_failure
|
58
|
+
CONFIRM_CHANNEL_POOL << ch unless ch.nil?
|
59
|
+
else
|
60
|
+
CHANNEL_POOL << ch unless ch.nil?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_channel(raise_on_failure)
|
66
|
+
begin
|
67
|
+
if raise_on_failure
|
68
|
+
ch = CONFIRM_CHANNEL_POOL.pop(true)
|
69
|
+
else
|
70
|
+
ch = CHANNEL_POOL.pop(true)
|
71
|
+
end
|
72
|
+
rescue ThreadError
|
73
|
+
ch = CONN.create_channel
|
58
74
|
end
|
59
75
|
end
|
60
76
|
end
|
@@ -292,6 +292,10 @@ describe Emque::Producing::Message do
|
|
292
292
|
let(:message) { TestMessageDontRaiseOnFailure.new() }
|
293
293
|
let(:publisher) { TestPublisher.new }
|
294
294
|
|
295
|
+
it "sets raise_on_failure to false" do
|
296
|
+
expect(message.raise_on_failure?).to be(false)
|
297
|
+
end
|
298
|
+
|
295
299
|
it "catches exceptions from publisher" do
|
296
300
|
allow(Emque::Producing).to receive(:publisher) { raise TestPublisher::InvalidMessageError }
|
297
301
|
|
@@ -321,13 +325,16 @@ describe Emque::Producing::Message do
|
|
321
325
|
|
322
326
|
expect{message.publish(publisher)}.to raise_error(TestMessageDontRaiseOnFailure::DontIgnoreThisError)
|
323
327
|
end
|
324
|
-
|
325
328
|
end
|
326
329
|
|
327
330
|
describe "when true" do
|
328
331
|
let(:message) { TestMessage.new(:test_id => 1) }
|
329
332
|
let(:publisher) { TestPublisher.new }
|
330
333
|
|
334
|
+
it "sets raise_on_failure to true" do
|
335
|
+
expect(message.raise_on_failure?).to be(true)
|
336
|
+
end
|
337
|
+
|
331
338
|
it "doesn't catch exceptions from publisher" do
|
332
339
|
allow(Emque::Producing).to receive(:publisher) { raise TestPublisher::InvalidMessageError }
|
333
340
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emque-producing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-06-01 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: oj
|