active_publisher 0.3.0-java → 0.4.0-java
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: 38225a42d598f22ae2b41480cd58fb93463789ed
|
4
|
+
data.tar.gz: b1788dee289e163797f8f992158beeb9462ea758
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a115986e6d53365a4da81b283f08dbab53f581c83deb0aad5748951f341e2f4f3e468d101c68cd10ef2c5b39a3e7c3db43c8290a603a21a665b4f298afa28a24
|
7
|
+
data.tar.gz: 73e551aad3e999e233d79dd6846116b3d1dcb21b258f91cc3a4b2220e51437a9e15d46f4fbf2ef019f4599c28831c30b76307e3878e5d01075141105607e6fd7
|
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
|
5
5
|
platform: java
|
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-28 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
version: '0'
|
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 features like automatially publishing lifecycle events for ActiveRecord models.
|