active_publisher 0.3.0 → 0.4.0.pre1
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: 7a21d679e539f7491e518f9de8ee35413c30271d
|
4
|
+
data.tar.gz: 25463b0153368b796740fc0d3d8445a7f58f6757
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c80ad112bf9d6d25a668b51412e42cf2941276aba76732cae1da85a144ddb2622d8e0cb0d30cf40949f48822d8a544d7df7b4e353a93911ed710511aa27415e3
|
7
|
+
data.tar.gz: b2d54a6bb7515fcdff35591691bf72aa376b87e3feb253e03cf095ceaf84de9339e490e35f96225d9e2f2c60230d35d4dc9dcc41a14a754cef835fa47eec411d
|
data/.travis.yml
CHANGED
data/lib/active_publisher.rb
CHANGED
@@ -16,6 +16,7 @@ require "active_publisher/connection"
|
|
16
16
|
module ActivePublisher
|
17
17
|
class UnknownMessageClassError < StandardError; end
|
18
18
|
class ExchangeMismatchError < StandardError; end
|
19
|
+
class FailedPublisherConfirms < StandardError; end
|
19
20
|
|
20
21
|
def self.configuration
|
21
22
|
@configuration ||= ::ActivePublisher::Configuration.new
|
@@ -62,7 +63,7 @@ module ActivePublisher
|
|
62
63
|
:persistent => false,
|
63
64
|
:routing_key => route,
|
64
65
|
}.merge(in_options)
|
65
|
-
|
66
|
+
|
66
67
|
if ::RUBY_PLATFORM == "java"
|
67
68
|
java_options = {}
|
68
69
|
java_options[:mandatory] = options.delete(:mandatory)
|
@@ -35,20 +35,28 @@ module ActivePublisher
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
def make_channel
|
39
|
+
channel = ::ActivePublisher::Connection.connection.create_channel
|
40
|
+
channel.confirm_select if ::ActivePublisher.configuration.publisher_confirms
|
41
|
+
channel
|
42
|
+
end
|
43
|
+
|
38
44
|
def start_thread
|
39
45
|
return if alive?
|
40
46
|
@thread = ::Thread.new do
|
41
47
|
loop do
|
42
48
|
# Sample the queue size so we don't shutdown when messages are in flight.
|
43
49
|
@sampled_queue_size = queue.size
|
44
|
-
current_messages = queue.pop_up_to(
|
50
|
+
current_messages = queue.pop_up_to(50)
|
45
51
|
|
46
52
|
begin
|
53
|
+
@channel ||= make_channel
|
54
|
+
|
47
55
|
# Only open a single connection for each group of messages to an exchange
|
48
56
|
current_messages.group_by(&:exchange_name).each do |exchange_name, messages|
|
49
57
|
begin
|
50
58
|
current_messages -= messages
|
51
|
-
|
59
|
+
publish_all(@channel, exchange_name, messages)
|
52
60
|
ensure
|
53
61
|
current_messages.concat(messages)
|
54
62
|
end
|
@@ -76,6 +84,40 @@ module ActivePublisher
|
|
76
84
|
end
|
77
85
|
end
|
78
86
|
end
|
87
|
+
|
88
|
+
def publish_all(channel, exchange_name, messages)
|
89
|
+
exchange = channel.topic(exchange_name)
|
90
|
+
potentially_retry = []
|
91
|
+
loop do
|
92
|
+
break if messages.empty?
|
93
|
+
message = messages.shift
|
94
|
+
|
95
|
+
fail ActivePublisher::UnknownMessageClassError, "bulk publish messages must be ActivePublisher::Message" unless message.is_a?(ActivePublisher::Message)
|
96
|
+
fail ActivePublisher::ExchangeMismatchError, "bulk publish messages must match publish_all exchange_name" if message.exchange_name != exchange_name
|
97
|
+
|
98
|
+
begin
|
99
|
+
options = ::ActivePublisher.publishing_options(message.route, message.options || {})
|
100
|
+
exchange.publish(message.payload, options)
|
101
|
+
potentially_retry << message
|
102
|
+
rescue
|
103
|
+
messages << message
|
104
|
+
raise
|
105
|
+
end
|
106
|
+
end
|
107
|
+
wait_for_confirms(channel, messages, potentially_retry)
|
108
|
+
end
|
109
|
+
|
110
|
+
def wait_for_confirms(channel, messages, potentially_retry)
|
111
|
+
return true unless channel.using_publisher_confirms?
|
112
|
+
if channel.method(:wait_for_confirms).arity > 0
|
113
|
+
channel.wait_for_confirms(::ActivePublisher.configuration.publisher_confirms_timeout)
|
114
|
+
else
|
115
|
+
channel.wait_for_confirms
|
116
|
+
end
|
117
|
+
rescue
|
118
|
+
messages.concat(potentially_retry)
|
119
|
+
raise
|
120
|
+
end
|
79
121
|
end
|
80
122
|
end
|
81
123
|
end
|
@@ -9,6 +9,7 @@ module ActivePublisher
|
|
9
9
|
:password,
|
10
10
|
:port,
|
11
11
|
:publisher_confirms,
|
12
|
+
:publisher_confirms_timeout,
|
12
13
|
:seconds_to_wait_for_graceful_shutdown,
|
13
14
|
:timeout,
|
14
15
|
:tls,
|
@@ -33,6 +34,7 @@ module ActivePublisher
|
|
33
34
|
:password => "guest",
|
34
35
|
:port => 5672,
|
35
36
|
:publisher_confirms => false,
|
37
|
+
:publisher_confirms_timeout => 5_000, #specified as a number of milliseconds
|
36
38
|
:seconds_to_wait_for_graceful_shutdown => 30,
|
37
39
|
:timeout => 1,
|
38
40
|
:tls => false,
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_publisher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brian Stien
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: exe
|
14
14
|
cert_chain: []
|
15
|
-
date: 2017-
|
15
|
+
date: 2017-06-23 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: bunny
|
@@ -145,12 +145,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
145
|
version: '0'
|
146
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
147
|
requirements:
|
148
|
-
- - "
|
148
|
+
- - ">"
|
149
149
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
150
|
+
version: 1.3.1
|
151
151
|
requirements: []
|
152
152
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.6.
|
153
|
+
rubygems_version: 2.6.12
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: Aims to make publishing work across MRI and jRuby painless and add some nice
|