bbk-amqp 1.0.0.79544 → 1.0.0.79546

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
  SHA256:
3
- metadata.gz: 93d7807a9dfeb65b4579d7db4993c28b2a73f7792c0cc2ce34d6f6b432754d6d
4
- data.tar.gz: ebd605cba0dbfd1ba630e7ec12a9d7f8c69689aa0e7d5c5cbee88a85779fca46
3
+ metadata.gz: ff8bcca2839ed6b799122ae45b7815d91d6241ab3f42b3645ec17e5bbabb0320
4
+ data.tar.gz: 735a3c4c4718de1def889bf9e701fcf847ffc9dfb406a14ccc705d64e9290763
5
5
  SHA512:
6
- metadata.gz: bceb60e98752cd3b27bfa283b88977ea9acc76effbcd543ce79658b1538196eb327f7b8e2a73c685a9d5730b125444c1c9cea6b35f37a598ef37653025804796
7
- data.tar.gz: 4d76301d6c3d9bb301e51d2b86a51089198f69accce1b36f595f486f15ce9d726ae8aeabae94b1aa0bef666a0748e54f8748bb570fab8828c90683b3daa98a7f
6
+ metadata.gz: 61c04f60792a0bcfcb28a0d2ca0e09a2eb3c46e7271bb73eb089d262397416c76d73ea2859b6e7e19f2450af82c17eed513f5bb40441141c694bf076afb48b4c
7
+ data.tar.gz: 9e7de36978f68bfdbe127059c4c9e7c1fe21a95a6c855c9b9e540ebc3561b933eea41d2ae66b262cec08cdcb5edeeb8437cea56f6884f22b25f5e1fb62fc9568
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bbk-amqp (1.0.0.79544)
4
+ bbk-amqp (1.0.0.79546)
5
5
  activesupport (~> 6.0)
6
6
  bbk-utils (> 1.0.1)
7
7
  bunny (>= 2.19.0)
@@ -1,17 +1,18 @@
1
1
  # frozen_string_literal: true
2
+ require 'bbk/amqp/rejection_policies/requeue'
2
3
 
3
4
  module BBK
4
5
  module AMQP
5
6
  class Consumer
6
7
 
7
- attr_reader :connection, :queue_name, :queue, :options, :logger
8
+ attr_reader :connection, :queue_name, :queue, :rejection_policy, :options, :logger
8
9
 
9
10
  DEFAULT_OPTIONS = {
10
11
  consumer_pool_size: 3,
11
12
  consumer_pool_abort_on_exception: true,
12
13
  prefetch_size: 10,
13
- requeue_on_reject: false,
14
- consumer_tag: nil
14
+ consumer_tag: nil,
15
+ rejection_policy: RejectionPolicies::Requeue.new
15
16
  }.freeze
16
17
 
17
18
  PROTOCOLS = %w[mq amqp amqps].freeze
@@ -28,6 +29,7 @@ module BBK
28
29
  @queue_name = @queue&.name || queue_name
29
30
 
30
31
  @options = DEFAULT_OPTIONS.merge(options)
32
+ @rejection_policy = @options.delete(:rejection_policy)
31
33
 
32
34
  logger = @options.fetch(:logger, BBK::AMQP.logger)
33
35
  logger = logger.respond_to?(:tagged) ? logger : ActiveSupport::TaggedLogging.new(logger)
@@ -47,7 +49,7 @@ module BBK
47
49
  ch.prefetch(options[:prefetch_size])
48
50
  end
49
51
 
50
- @logger.add_tags "Ch##{@channel.id}"
52
+ logger.add_tags "Ch##{@channel.id}"
51
53
 
52
54
  @queue ||= @channel.queue(queue_name, passive: true)
53
55
 
@@ -82,11 +84,8 @@ module BBK
82
84
 
83
85
  # Nack incoming message
84
86
  # @param incoming [BBK::AMQP::Message] nack procesing message
85
- def nack(incoming, *args, error: nil, requeue: nil, **_kwargs)
86
- logger.debug "Reject message #{incoming.headers[:type]}[#{incoming.headers[:message_id]}] delivery tag: #{incoming.delivery_info[:delivery_tag].to_i}. Error: #{error.inspect}"
87
- requeue_message = requeue.nil? ? options[:requeue_on_reject] : requeue
88
- incoming.delivery_info[:channel].reject incoming.delivery_info[:delivery_tag],
89
- requeue_message
87
+ def nack(incoming, *args, error: nil, **_kwargs)
88
+ rejection_policy.call(incoming, error)
90
89
  end
91
90
 
92
91
  # stop consuming messages
@@ -0,0 +1,20 @@
1
+ module BBK
2
+ module AMQP
3
+ module RejectionPolicies
4
+ class Reject
5
+
6
+ attr_reader :logger
7
+
8
+ def initialize(logger: BBK::Utils::Logger.default)
9
+ @logger = logger
10
+ end
11
+
12
+ def call(message, error)
13
+ logger.debug "Reject message #{message.headers[:type]}[#{message.headers[:message_id]}] delivery tag: #{message.delivery_info[:delivery_tag].to_i}. Error: #{error.inspect}"
14
+ message.delivery_info[:channel].reject message.delivery_info[:delivery_tag], false
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ module BBK
2
+ module AMQP
3
+ module RejectionPolicies
4
+ class Requeue
5
+
6
+ attr_reader :logger
7
+
8
+ def initialize(logger: BBK::Utils::Logger.default)
9
+ @logger = logger
10
+ end
11
+
12
+ def call(message, error)
13
+ logger.debug "Requeue message #{message.headers[:type]}[#{message.headers[:message_id]}] delivery tag: #{message.delivery_info[:delivery_tag].to_i}. Error: #{error.inspect}"
14
+ message.delivery_info[:channel].reject message.delivery_info[:delivery_tag], true
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
data/lib/bbk/amqp.rb CHANGED
@@ -13,6 +13,8 @@ require 'bbk/amqp/route_info'
13
13
  require 'bbk/amqp/domains_set'
14
14
  require 'bbk/amqp/domains/exchange'
15
15
  require 'bbk/amqp/domains/by_block'
16
+ require 'bbk/amqp/rejection_policies/reject'
17
+ require 'bbk/amqp/rejection_policies/requeue'
16
18
  require_relative 'bunny_patch'
17
19
 
18
20
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbk-amqp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.79544
4
+ version: 1.0.0.79546
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samoylenko Yuri
@@ -211,6 +211,8 @@ files:
211
211
  - lib/bbk/amqp/domains_set.rb
212
212
  - lib/bbk/amqp/message.rb
213
213
  - lib/bbk/amqp/publisher.rb
214
+ - lib/bbk/amqp/rejection_policies/reject.rb
215
+ - lib/bbk/amqp/rejection_policies/requeue.rb
214
216
  - lib/bbk/amqp/route_info.rb
215
217
  - lib/bbk/amqp/spec.rb
216
218
  - lib/bbk/amqp/spec/rabbit_helper.rb