bbk-amqp 1.0.0.72921 → 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: 45b2c6b051f57110604b1d26cf2630d3366c13011706fbe0fb9197900252b6e7
4
- data.tar.gz: 62ea34dcbb14ab912ceebc56be7fc70f9e5e7fbc613f3009cf7cf88d19504467
3
+ metadata.gz: ff8bcca2839ed6b799122ae45b7815d91d6241ab3f42b3645ec17e5bbabb0320
4
+ data.tar.gz: 735a3c4c4718de1def889bf9e701fcf847ffc9dfb406a14ccc705d64e9290763
5
5
  SHA512:
6
- metadata.gz: 58de9988370d0e84ed2a5be0b499376c7bd6defbb60798bf6b0d74f8ee044d49ab0b4ded2749ea6cd422428914e87a0e2622a41425581361c16227c9d44e2b7f
7
- data.tar.gz: b5ecbe8e54c6473b8bf223a68a6a155d42b1ec8b78aa4e6c3e16ecccb99e8040f55a111dc9d6dc7e8f5212301a9ec6b147deabb1ecadf6923b2222f51ef97fc9
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.72921)
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
@@ -33,12 +33,16 @@ module BBK
33
33
  headers[:reply_to]
34
34
  end
35
35
 
36
+ def user_id
37
+ headers[:user_id]
38
+ end
39
+
36
40
  def ack(*args, answer: nil, **kwargs)
37
41
  consumer.ack(self, *args, answer: answer, **kwargs)
38
42
  end
39
43
 
40
44
  def nack(*args, error: nil, **kwargs)
41
- consumer.ack(self, *args, error: error, **kwargs)
45
+ consumer.nack(self, *args, error: error, **kwargs)
42
46
  end
43
47
 
44
48
  end
@@ -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,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbk-amqp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.72921
4
+ version: 1.0.0.79546
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samoylenko Yuri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-12 00:00:00.000000000 Z
11
+ date: 2022-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -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