bbk-amqp 1.0.0.76397 → 1.0.0.81661
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/bbk/amqp/consumer.rb +10 -10
- data/lib/bbk/amqp/message.rb +1 -1
- data/lib/bbk/amqp/rejection_policies/reject.rb +20 -0
- data/lib/bbk/amqp/rejection_policies/requeue.rb +19 -0
- data/lib/bbk/amqp.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7383eceef602da4c6dfb5c6bfa31b161f7f97fc75391f0215b769a2807e644ef
|
4
|
+
data.tar.gz: 56b88eba1ac97a16183d1e9471462adfa2d99c38a24678b9fafde8ebec4aaa0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ce4f910058005cb9ca048810370cf9447bae4fe176bcd0fcaa4cdff35271aa55c3b94abe11e6a28d3c16f825f414d10c93f8d1d99157554070d5b70d887e5e8
|
7
|
+
data.tar.gz: bfc30528d0873325b5b860f7d18a206b5cd52a05edb2df83f7c3a4d6b95625a4fd1367a7af0ef5f8ebf07827be9464388dc6d4121d0e62ae62928e87976c81ce
|
data/Gemfile.lock
CHANGED
data/lib/bbk/amqp/consumer.rb
CHANGED
@@ -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
|
-
|
14
|
-
|
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
|
-
|
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,
|
86
|
-
|
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
|
data/lib/bbk/amqp/message.rb
CHANGED
@@ -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.
|
4
|
+
version: 1.0.0.81661
|
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-
|
11
|
+
date: 2022-04-08 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
|