bbk-amqp 1.0.0.79544 → 1.0.0.82233

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: 1c4691eeb1a8c742af5a8678ed18f4ab9c198765e6e189716b972bfcdde3c409
4
+ data.tar.gz: 8fac5db1263e73f8e2fa5bf3aed867d297933cfd981ec364b559a5bc20959dc1
5
5
  SHA512:
6
- metadata.gz: bceb60e98752cd3b27bfa283b88977ea9acc76effbcd543ce79658b1538196eb327f7b8e2a73c685a9d5730b125444c1c9cea6b35f37a598ef37653025804796
7
- data.tar.gz: 4d76301d6c3d9bb301e51d2b86a51089198f69accce1b36f595f486f15ce9d726ae8aeabae94b1aa0bef666a0748e54f8748bb570fab8828c90683b3daa98a7f
6
+ metadata.gz: fa1ea15621d89c371748dc3b1227efcd2162d13ba10e761d0520cdaf51b97590f9af8205a119b15eb1e9f6ae897c9edad8b5b8aca44c9046c80e8233f0c7f651
7
+ data.tar.gz: 664f3ad951d06369bcbc3c1994b986a44a83ef32732eaf8ff95ecd4657c035de08e54dbcc49071e5df9c3cc6431e0d176322714d0c37e934d3326039aa9ec36e
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.82233)
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,14 +49,15 @@ 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
 
54
56
  subscribe_opts = {
55
57
  block: false,
56
58
  manual_ack: true,
57
- consumer_tag: options[:consumer_tag]
59
+ consumer_tag: options[:consumer_tag],
60
+ exclusive: options.fetch(:exclusive, false)
58
61
  }.compact
59
62
 
60
63
  logger.info 'Starting...'
@@ -82,11 +85,8 @@ module BBK
82
85
 
83
86
  # Nack incoming message
84
87
  # @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
88
+ def nack(incoming, *args, error: nil, **_kwargs)
89
+ rejection_policy.call(incoming, error)
90
90
  end
91
91
 
92
92
  # stop consuming messages
@@ -8,7 +8,7 @@ module BBK
8
8
  # Publisher send amqp messages
9
9
  class Publisher
10
10
 
11
- HEADER_PROP_FIELDS = %i[user_id message_id reply_to correlation_id].freeze
11
+ HEADER_PROP_FIELDS = %i[message_id reply_to correlation_id].freeze
12
12
  PROTOCOLS = %w[mq amqp amqps].freeze
13
13
 
14
14
  attr_reader :connection, :domains, :logger, :channel, :ack_map, :sended_messages, :channel
@@ -72,7 +72,7 @@ module BBK
72
72
  mandatory: true,
73
73
  routing_key: routing_key,
74
74
  headers: message.headers,
75
- user_id: client_name, # если есть в headers, то на следующей строке будет перетерто
75
+ # user_id: client_name,
76
76
  **message.headers.select {|k| HEADER_PROP_FIELDS.include? k }.compact
77
77
  }.merge(options).symbolize_keys
78
78
  send_message(exchange, routing_key, message.payload, properties)
@@ -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.79544
4
+ version: 1.0.0.82233
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-03-17 00:00:00.000000000 Z
11
+ date: 2022-04-14 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