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: d68de1406c1a8d12f48d204706891b85f92f8f38
4
- data.tar.gz: 7f40ae37793a0e3cd116a8697c0d409e22b54939
3
+ metadata.gz: 38225a42d598f22ae2b41480cd58fb93463789ed
4
+ data.tar.gz: b1788dee289e163797f8f992158beeb9462ea758
5
5
  SHA512:
6
- metadata.gz: e1d9238b86529974e3bbc6793e557b1066b672e8d158039e1b38aa763eb1d1331bacfef20664cb896b91d467a1823622473402cad2087087411f383ec7db7433
7
- data.tar.gz: c0bb868985c0e0aaa1fb90551397700688fa06423649e7285606e9c6741db6a87d294cdcaa55fbe502d63406c0f18dbaba0ee16602830932e290e80e5bf6ef36
6
+ metadata.gz: a115986e6d53365a4da81b283f08dbab53f581c83deb0aad5748951f341e2f4f3e468d101c68cd10ef2c5b39a3e7c3db43c8290a603a21a665b4f298afa28a24
7
+ data.tar.gz: 73e551aad3e999e233d79dd6846116b3d1dcb21b258f91cc3a4b2220e51437a9e15d46f4fbf2ef019f4599c28831c30b76307e3878e5d01075141105607e6fd7
@@ -1,15 +1,11 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0
4
- - 2.1
5
3
  - 2.2
4
+ - 2.3
5
+ - 2.4
6
6
  - jruby-1.7
7
- - jruby-9.1.0.0
8
- - jruby-head
7
+ - jruby-9.1.12.0
9
8
  services:
10
9
  - rabbitmq
11
10
  sudo: false
12
11
  cache: bundler
13
- matrix:
14
- allow_failures:
15
- - rvm: jruby-head
@@ -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(20)
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
- ::ActivePublisher.publish_all(exchange_name, messages)
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,
@@ -1,3 +1,3 @@
1
1
  module ActivePublisher
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
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.3.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-02-07 00:00:00.000000000 Z
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.10
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.