active_publisher 0.2.0.pre-java → 0.2.1-java
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.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf0ffccc8074e99fc31d1e5b0a0563e969b59492
|
4
|
+
data.tar.gz: b6b3d8c06b6338f902705f4304ce3e8c254b4dda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9945b219ab735188e7eae81f0c2038a226f4840dab441e257ad27af6f872a8d40285f5341a0adb8c96d75bdaa058d0c69840eb64c7f731237c5517322035534
|
7
|
+
data.tar.gz: f410bf494ace9d0574e014cdc9bd278949851dc5c3cdf1909b90dee23caee3113cc98d7c6652a06764aa536e4cdb2c9f45fb6b2f1d7f1722fb9a051d1553df93
|
@@ -32,7 +32,10 @@ module ActivePublisher
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def size
|
35
|
-
queue
|
35
|
+
# Requests might be in flight (out of the queue, but not yet published), so taking the max should be
|
36
|
+
# good enough to make sure we're honest about the actual queue size.
|
37
|
+
return queue.size if consumer.nil?
|
38
|
+
[queue.size, consumer.sampled_queue_size].max
|
36
39
|
end
|
37
40
|
|
38
41
|
private
|
@@ -42,9 +45,6 @@ module ActivePublisher
|
|
42
45
|
@supervisor = ::Thread.new do
|
43
46
|
loop do
|
44
47
|
unless consumer.alive?
|
45
|
-
# We might need to requeue the last messages popped
|
46
|
-
current_consumer_messages = consumer.current_messages
|
47
|
-
queue.concat(current_consumer_messages) unless current_consumer_messages.empty?
|
48
48
|
consumer.kill
|
49
49
|
@consumer = ::ActivePublisher::Async::InMemoryAdapter::ConsumerThread.new(queue)
|
50
50
|
end
|
@@ -2,7 +2,7 @@ module ActivePublisher
|
|
2
2
|
module Async
|
3
3
|
module InMemoryAdapter
|
4
4
|
class ConsumerThread
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :thread, :queue, :sampled_queue_size
|
6
6
|
|
7
7
|
if ::RUBY_PLATFORM == "java"
|
8
8
|
NETWORK_ERRORS = [::MarchHare::Exception, ::Java::ComRabbitmqClient::AlreadyClosedException, ::Java::JavaIo::IOException].freeze
|
@@ -11,8 +11,8 @@ module ActivePublisher
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def initialize(listen_queue)
|
14
|
-
@current_messages = []
|
15
14
|
@queue = listen_queue
|
15
|
+
@sampled_queue_size = queue.size
|
16
16
|
start_thread
|
17
17
|
end
|
18
18
|
|
@@ -39,43 +39,36 @@ module ActivePublisher
|
|
39
39
|
return if alive?
|
40
40
|
@thread = ::Thread.new do
|
41
41
|
loop do
|
42
|
-
#
|
43
|
-
@
|
42
|
+
# Sample the queue size so we don't shutdown when messages are in flight.
|
43
|
+
@sampled_queue_size = queue.size
|
44
|
+
current_messages = queue.pop_up_to(20)
|
44
45
|
|
45
46
|
begin
|
46
47
|
# Only open a single connection for each group of messages to an exchange
|
47
|
-
|
48
|
-
@current_messages.group_by(&:exchange_name).each do |exchange_name, messages|
|
48
|
+
current_messages.group_by(&:exchange_name).each do |exchange_name, messages|
|
49
49
|
begin
|
50
|
+
current_messages -= messages
|
50
51
|
::ActivePublisher.publish_all(exchange_name, messages)
|
51
52
|
ensure
|
52
|
-
|
53
|
+
current_messages.concat(messages)
|
53
54
|
end
|
54
55
|
end
|
55
|
-
|
56
|
-
# Reset
|
57
|
-
@current_messages = []
|
58
56
|
rescue *NETWORK_ERRORS
|
59
57
|
# Sleep because connection is down
|
60
58
|
await_network_reconnect
|
61
|
-
@current_messages.concat(messages_to_retry)
|
62
59
|
|
63
60
|
# Requeue and try again.
|
64
|
-
queue.concat(
|
61
|
+
queue.concat(current_messages)
|
65
62
|
rescue => unknown_error
|
66
|
-
|
67
|
-
@current_messages.each do |message|
|
63
|
+
current_messages.each do |message|
|
68
64
|
# Degrade to single message publish ... or at least attempt to
|
69
65
|
begin
|
70
66
|
::ActivePublisher.publish(message.route, message.payload, message.exchange_name, message.options)
|
71
|
-
rescue
|
67
|
+
rescue
|
72
68
|
::ActivePublisher.configuration.error_handler.call(unknown_error, {:route => message.route, :payload => message.payload, :exchange_name => message.exchange_name, :options => message.options})
|
73
69
|
end
|
74
70
|
end
|
75
71
|
|
76
|
-
# Do not requeue the message because something else horrible happened.
|
77
|
-
@current_messages = []
|
78
|
-
|
79
72
|
# TODO: Find a way to bubble this out of the thread for logging purposes.
|
80
73
|
# Reraise the error out of the publisher loop. The Supervisor will restart the consumer.
|
81
74
|
raise unknown_error
|
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.2.
|
4
|
+
version: 0.2.1
|
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: 2016-
|
15
|
+
date: 2016-12-07 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
@@ -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: '0'
|
151
151
|
requirements: []
|
152
152
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.
|
153
|
+
rubygems_version: 2.4.8
|
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.
|