active_publisher 0.4.0.pre1-java → 1.0.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +0 -2
- data/active_publisher.gemspec +1 -0
- data/lib/active_publisher/async/in_memory_adapter/async_queue.rb +31 -10
- data/lib/active_publisher/async/in_memory_adapter/consumer_thread.rb +19 -17
- data/lib/active_publisher/async/in_memory_adapter.rb +2 -2
- data/lib/active_publisher/version.rb +1 -1
- data/lib/active_publisher.rb +7 -2
- metadata +21 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5af4607ffab1b83be825a72a22726e442ed1c3d5
|
4
|
+
data.tar.gz: 91c291269e965f25e2123177e6271f2fb7b13d92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5664f916eb23f5bd21aa9eaa58473639ace753bddf92d3f1441e5ae8e41dc98b6307bb442baa827ef2e1dc38e009133177c123151623ece55faf8e7c70d01a6
|
7
|
+
data.tar.gz: 7fa2ba9612e32d4c2cc021ba419000ed4fe3c7ef9c43ffca73fbd78430b960a530b2f6c7d4dd38e52fee8a6f4a0ba9b5c1cbe909235d644c6973e83c1ec99cfe
|
data/.travis.yml
CHANGED
data/active_publisher.gemspec
CHANGED
@@ -2,30 +2,48 @@ module ActivePublisher
|
|
2
2
|
module Async
|
3
3
|
module InMemoryAdapter
|
4
4
|
class AsyncQueue
|
5
|
+
# These strategies are used to determine what to do with messages when the queue is full.
|
6
|
+
# :raise - Raise an error and drop the message.
|
7
|
+
# :drop - Silently drop the message.
|
8
|
+
# :wait - Wait for space in the queue to become available.
|
9
|
+
BACK_PRESSURE_STRATEGIES = [:raise, :drop, :wait].freeze
|
10
|
+
|
5
11
|
include ::ActivePublisher::Logging
|
6
12
|
|
7
|
-
attr_accessor :
|
13
|
+
attr_accessor :back_pressure_strategy,
|
8
14
|
:max_queue_size,
|
9
15
|
:supervisor_interval
|
10
16
|
|
11
17
|
attr_reader :consumer, :queue, :supervisor
|
12
18
|
|
13
|
-
def initialize(
|
14
|
-
|
19
|
+
def initialize(back_pressure_strategy, max_queue_size, supervisor_interval)
|
20
|
+
self.back_pressure_strategy = back_pressure_strategy
|
15
21
|
@max_queue_size = max_queue_size
|
16
22
|
@supervisor_interval = supervisor_interval
|
17
23
|
@queue = ::MultiOpQueue::Queue.new
|
18
24
|
create_and_supervise_consumer!
|
19
25
|
end
|
20
26
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
return if drop_messages_when_queue_full
|
27
|
+
def back_pressure_strategy=(strategy)
|
28
|
+
fail ::ArgumentError, "Invalid back pressure strategy: #{strategy}" unless BACK_PRESSURE_STRATEGIES.include?(strategy)
|
29
|
+
@back_pressure_strategy = strategy
|
30
|
+
end
|
26
31
|
|
27
|
-
|
28
|
-
|
32
|
+
def push(message)
|
33
|
+
if queue.size >= max_queue_size
|
34
|
+
case back_pressure_strategy
|
35
|
+
when :drop
|
36
|
+
::ActiveSupport::Notifications.instrument "message_dropped.active_publisher"
|
37
|
+
return
|
38
|
+
when :raise
|
39
|
+
::ActiveSupport::Notifications.instrument "message_dropped.active_publisher"
|
40
|
+
fail ::ActivePublisher::Async::InMemoryAdapter::UnableToPersistMessageError, "Queue is full, messages will be dropped."
|
41
|
+
when :wait
|
42
|
+
::ActiveSupport::Notifications.instrument "wait_for_async_queue.active_publisher" do
|
43
|
+
# This is a really crappy way to wait
|
44
|
+
sleep 0.01 until queue.size < max_queue_size
|
45
|
+
end
|
46
|
+
end
|
29
47
|
end
|
30
48
|
|
31
49
|
queue.push(message)
|
@@ -49,6 +67,9 @@ module ActivePublisher
|
|
49
67
|
@consumer = ::ActivePublisher::Async::InMemoryAdapter::ConsumerThread.new(queue)
|
50
68
|
end
|
51
69
|
|
70
|
+
# Notify the current queue size.
|
71
|
+
::ActiveSupport::Notifications.instrument "async_queue_size.active_publisher", queue.size
|
72
|
+
|
52
73
|
# Pause before checking the consumer again.
|
53
74
|
sleep supervisor_interval
|
54
75
|
end
|
@@ -86,25 +86,27 @@ module ActivePublisher
|
|
86
86
|
end
|
87
87
|
|
88
88
|
def publish_all(channel, exchange_name, messages)
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
89
|
+
::ActiveSupport::Notifications.instrument "message_published.active_publisher", :message_count => messages.size do
|
90
|
+
exchange = channel.topic(exchange_name)
|
91
|
+
potentially_retry = []
|
92
|
+
loop do
|
93
|
+
break if messages.empty?
|
94
|
+
message = messages.shift
|
95
|
+
|
96
|
+
fail ActivePublisher::UnknownMessageClassError, "bulk publish messages must be ActivePublisher::Message" unless message.is_a?(ActivePublisher::Message)
|
97
|
+
fail ActivePublisher::ExchangeMismatchError, "bulk publish messages must match publish_all exchange_name" if message.exchange_name != exchange_name
|
98
|
+
|
99
|
+
begin
|
100
|
+
options = ::ActivePublisher.publishing_options(message.route, message.options || {})
|
101
|
+
exchange.publish(message.payload, options)
|
102
|
+
potentially_retry << message
|
103
|
+
rescue
|
104
|
+
messages << message
|
105
|
+
raise
|
106
|
+
end
|
105
107
|
end
|
108
|
+
wait_for_confirms(channel, messages, potentially_retry)
|
106
109
|
end
|
107
|
-
wait_for_confirms(channel, messages, potentially_retry)
|
108
110
|
end
|
109
111
|
|
110
112
|
def wait_for_confirms(channel, messages, potentially_retry)
|
@@ -18,11 +18,11 @@ module ActivePublisher
|
|
18
18
|
|
19
19
|
attr_reader :async_queue
|
20
20
|
|
21
|
-
def initialize(
|
21
|
+
def initialize(back_pressure_strategy = :raise, max_queue_size = 100_000, supervisor_interval = 0.2)
|
22
22
|
logger.info "Starting in-memory publisher adapter"
|
23
23
|
|
24
24
|
@async_queue = ::ActivePublisher::Async::InMemoryAdapter::AsyncQueue.new(
|
25
|
-
|
25
|
+
back_pressure_strategy,
|
26
26
|
max_queue_size,
|
27
27
|
supervisor_interval
|
28
28
|
)
|
data/lib/active_publisher.rb
CHANGED
@@ -3,6 +3,7 @@ if ::RUBY_PLATFORM == "java"
|
|
3
3
|
else
|
4
4
|
require "bunny"
|
5
5
|
end
|
6
|
+
require "active_support"
|
6
7
|
require "thread"
|
7
8
|
|
8
9
|
require "active_publisher/logging"
|
@@ -34,7 +35,9 @@ module ActivePublisher
|
|
34
35
|
# @param [Hash] options hash to set message parameters (e.g. headers)
|
35
36
|
def self.publish(route, payload, exchange_name, options = {})
|
36
37
|
with_exchange(exchange_name) do |exchange|
|
37
|
-
|
38
|
+
::ActiveSupport::Notifications.instrument "message_published.active_publisher" do
|
39
|
+
exchange.publish(payload, publishing_options(route, options))
|
40
|
+
end
|
38
41
|
end
|
39
42
|
end
|
40
43
|
|
@@ -48,7 +51,9 @@ module ActivePublisher
|
|
48
51
|
fail ActivePublisher::ExchangeMismatchError, "bulk publish messages must match publish_all exchange_name" if message.exchange_name != exchange_name
|
49
52
|
|
50
53
|
begin
|
51
|
-
|
54
|
+
::ActiveSupport::Notifications.instrument "message_published.active_publisher" do
|
55
|
+
exchange.publish(message.payload, publishing_options(message.route, message.options || {}))
|
56
|
+
end
|
52
57
|
rescue
|
53
58
|
messages << message
|
54
59
|
raise
|
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: 1.0.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-09-07 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
requirement: !ruby/object:Gem::Requirement
|
@@ -28,6 +28,20 @@ dependencies:
|
|
28
28
|
- - "~>"
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
version: '2.7'
|
31
|
+
- !ruby/object:Gem::Dependency
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '3.2'
|
37
|
+
name: activesupport
|
38
|
+
prerelease: false
|
39
|
+
type: :runtime
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '3.2'
|
31
45
|
- !ruby/object:Gem::Dependency
|
32
46
|
requirement: !ruby/object:Gem::Requirement
|
33
47
|
requirements:
|
@@ -145,13 +159,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
145
159
|
version: '0'
|
146
160
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
161
|
requirements:
|
148
|
-
- - "
|
162
|
+
- - ">="
|
149
163
|
- !ruby/object:Gem::Version
|
150
|
-
version:
|
164
|
+
version: '0'
|
151
165
|
requirements: []
|
152
166
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.6.
|
167
|
+
rubygems_version: 2.6.13
|
154
168
|
signing_key:
|
155
169
|
specification_version: 4
|
156
|
-
summary: Aims to make publishing work across MRI and jRuby painless and add some nice
|
170
|
+
summary: Aims to make publishing work across MRI and jRuby painless and add some nice
|
171
|
+
features like automatially publishing lifecycle events for ActiveRecord models.
|
157
172
|
test_files: []
|