action_subscriber 1.7.0.pre0-java → 2.0.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: 68350fb402dffbd21fecee459016821768b6fb58
4
- data.tar.gz: 79bf21dd81ef09d53481cf1dcba66be42c5f63e1
3
+ metadata.gz: 3b735e55441bb363ffee337ccac2f4c035c9a2ab
4
+ data.tar.gz: aa191fc25e00b272dcce56aa44fc637613f1ecb5
5
5
  SHA512:
6
- metadata.gz: 0315e70ef922b4aceedafc60d510973e548f4ccd2435edc007b9e88f35a46fc03e95405bf0824471c085df687f6c313696dbf0263fa8a35cf41777939a9d4ce0
7
- data.tar.gz: be59f6fee787b749a0457e268265eae8a64130e7d2747cc8356d34fba48fe2b729dd8d6f94ff0ba3797d6016524c5d3d2588b1392364f73d4af0b9d3274a0fe6
6
+ metadata.gz: e17ca1faf6ceb7a0c0ac069617e06ce6f0514aead48023c81ad5612d85ec9e713c5fecab8cd994c1c1dcaa9b8322c4742cb64755498227600888ecd0a1da2104
7
+ data.tar.gz: baa20e82dab735f117c8c80304f706735c02822979bb02e299c6c5daf70929ddc3de95ae65f48a0adce3e5d80cbd6bff9eebae8b4f2adb00e71af5c964e1ed9c
@@ -66,7 +66,7 @@ module ActionSubscriber
66
66
  def enqueue_env(threadpool, env)
67
67
  logger.info "RECEIVED #{env.message_id} from #{env.queue}"
68
68
  threadpool.async(env) do |env|
69
- ::ActiveSupport::Notifications.instrument "process_event.action_subscriber", :subscriber => env.subscriber.to_s, :routing_key => env.routing_key do
69
+ ::ActiveSupport::Notifications.instrument "process_event.action_subscriber", :subscriber => env.subscriber.to_s, :routing_key => env.routing_key, :queue => env.queue do
70
70
  ::ActionSubscriber.config.middleware.call(env)
71
71
  end
72
72
  end
@@ -67,7 +67,7 @@ module ActionSubscriber
67
67
  def enqueue_env(threadpool, env)
68
68
  logger.info "RECEIVED #{env.message_id} from #{env.queue}"
69
69
  threadpool.async(env) do |env|
70
- ::ActiveSupport::Notifications.instrument "process_event.action_subscriber", :subscriber => env.subscriber.to_s, :routing_key => env.routing_key do
70
+ ::ActiveSupport::Notifications.instrument "process_event.action_subscriber", :subscriber => env.subscriber.to_s, :routing_key => env.routing_key, :queue => env.queue do
71
71
  ::ActionSubscriber.config.middleware.call(env)
72
72
  end
73
73
  end
@@ -16,8 +16,9 @@ module ActionSubscriber
16
16
  next_attempt = get_last_attempt_number(env) + 1
17
17
  ttl = SCHEDULE[next_attempt]
18
18
  return unless ttl
19
- with_exchange(env, ttl) do |exchange|
20
- exchange.publish(env.encoded_payload, retry_options(env, next_attempt))
19
+ retry_queue_name = "#{env.queue}.retry_#{ttl}"
20
+ with_exchange(env, ttl, retry_queue_name) do |exchange|
21
+ exchange.publish(env.encoded_payload, retry_options(env, next_attempt, retry_queue_name))
21
22
  end
22
23
  end
23
24
 
@@ -30,26 +31,27 @@ module ActionSubscriber
30
31
  def self.retry_headers(env, attempt)
31
32
  env.headers.reject do |key, val|
32
33
  key == "x-death"
33
- end.merge({"as-attempt" => attempt.to_s})
34
+ end.merge({
35
+ "as-attempt" => attempt.to_s,
36
+ "x-dead-letter-routing-key" => env.queue,
37
+ })
34
38
  end
35
39
 
36
- def self.retry_options(env, attempt)
40
+ def self.retry_options(env, attempt, retry_queue_name)
37
41
  {
38
42
  :content_type => env.content_type,
39
- :routing_key => env.routing_key,
43
+ :routing_key => retry_queue_name,
40
44
  :headers => retry_headers(env, attempt),
41
45
  }
42
46
  end
43
47
 
44
- def self.with_exchange(env, ttl)
45
- exchange_retry_name = "#{env.exchange}_retry_#{ttl}"
46
- queue_retry_name = "#{env.queue}_retry_#{ttl}"
48
+ def self.with_exchange(env, ttl, retry_queue_name)
47
49
  channel = RabbitConnection.subscriber_connection.create_channel
48
50
  begin
49
51
  channel.confirm_select
50
- exchange = channel.topic(exchange_retry_name)
51
- queue = channel.queue(queue_retry_name, :arguments => {"x-dead-letter-exchange" => env.exchange, "x-message-ttl" => ttl})
52
- queue.bind(exchange, :routing_key => env.routing_key)
52
+ # an empty string is the default exchange [see bunny docs](http://rubybunny.info/articles/exchanges.html#default_exchange)
53
+ exchange = channel.topic("")
54
+ queue = channel.queue(retry_queue_name, :arguments => {"x-dead-letter-exchange" => "", "x-message-ttl" => ttl, "x-dead-letter-routing-key" => env.queue})
53
55
  yield(exchange)
54
56
  channel.wait_for_confirms
55
57
  ensure
@@ -1,3 +1,5 @@
1
+ require "securerandom"
2
+
1
3
  module ActionSubscriber
2
4
  module Middleware
3
5
  class Env
@@ -30,7 +32,7 @@ module ActionSubscriber
30
32
  @encoded_payload = encoded_payload
31
33
  @exchange = properties.fetch(:exchange)
32
34
  @headers = properties.fetch(:headers) || {}
33
- @message_id = properties.fetch(:message_id) || ::Random.new.bytes(3).unpack("H*")[0]
35
+ @message_id = properties.fetch(:message_id) || ::SecureRandom.hex(3)
34
36
  @queue = properties.fetch(:queue)
35
37
  @routing_key = properties.fetch(:routing_key)
36
38
  @subscriber = subscriber
@@ -1,3 +1,3 @@
1
1
  module ActionSubscriber
2
- VERSION = "1.7.0.pre0"
2
+ VERSION = "2.0.0"
3
3
  end
data/spec/spec_helper.rb CHANGED
@@ -10,9 +10,11 @@ require 'active_record'
10
10
 
11
11
  # Require spec support files
12
12
  require 'support/user_subscriber'
13
-
14
13
  require 'action_subscriber/rspec'
15
14
 
15
+ # Silence the Logger
16
+ ::ActionSubscriber::Logging.initialize_logger(nil)
17
+
16
18
  RSpec.configure do |config|
17
19
  config.mock_with :rspec do |mocks|
18
20
  mocks.verify_partial_doubles = true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_subscriber
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0.pre0
4
+ version: 2.0.0
5
5
  platform: java
6
6
  authors:
7
7
  - Brian Stien
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2015-12-23 00:00:00.000000000 Z
15
+ date: 2016-01-11 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  requirement: !ruby/object:Gem::Requirement
@@ -264,9 +264,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
264
264
  version: '0'
265
265
  required_rubygems_version: !ruby/object:Gem::Requirement
266
266
  requirements:
267
- - - ">"
267
+ - - ">="
268
268
  - !ruby/object:Gem::Version
269
- version: 1.3.1
269
+ version: '0'
270
270
  requirements: []
271
271
  rubyforge_project:
272
272
  rubygems_version: 2.5.0