active_publisher 0.2.0.pre → 0.2.1.pre.pre1
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: 776896ecf47853a70286c608f9e8201d1b33f2da
|
|
4
|
+
data.tar.gz: 5feed515e2207aaa5503582ebd4aa81d69970591
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6b4c8139224c0f17a8e3a11ea45784f02b2c55dd1c8eb1b86d330c44fc5884306c96545aa64ab44a25d41b9b318be735ba2ecd4b1dd5537cc561d7a52a60347b
|
|
7
|
+
data.tar.gz: 367df378599133b6a1e644fb445a71b22cbe9fef84b95a8fb7cb10c720c6e473e26b1d87dbbbb840e500ed6b9ee19047d7a761dd62e93e186bd25f22901ca5ab
|
|
@@ -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.pre.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: 2016-
|
|
15
|
+
date: 2016-12-02 00:00:00.000000000 Z
|
|
16
16
|
dependencies:
|
|
17
17
|
- !ruby/object:Gem::Dependency
|
|
18
18
|
name: bunny
|