bbk-amqp 1.0.0.82260 → 1.0.0.92190

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: 2f79016d5cab4da9644abbb93ad71897c24a93a473bd21cf223ea3fd6eebaa7d
4
- data.tar.gz: bcbcf9d71e111c5b6a8c9efe48ead69a46d0804890b6601be32571a57ee926d3
3
+ metadata.gz: afd08dd73c8fd2b53d6a27a01363edc0925d57839de9734f15d7ab892276a43b
4
+ data.tar.gz: 132d7b81a2874a9ba84596ec3b06a8932610f54ac052c731235c5d0855d0428a
5
5
  SHA512:
6
- metadata.gz: edcd402fc303d9e9fdd8c84c0b06a9b17a11da21fd662955c8ae5664a8a5c6bd1d7669380129d435a8ecc17f607ab6ef40eee25690e4904bb54db29c1fac3197
7
- data.tar.gz: 7fad342cafc572b1d747ae63db622b8b9a7db8fa880542b56a5628e9390316c959d187299eb2a5216053441251b40508554023e48896e7b1f608cbb74f51050c
6
+ metadata.gz: 7317bf1dd97e942523bf211bbd17a69e9d71d1402c59ace409c957a8d8b83b086761c0b2e3685d2d00578090d7ec2160cdebf4ce28cffe259333902fa8129225
7
+ data.tar.gz: 4bf82f34f60b7acda061a2d5787fb28268f60b8e57a319a4ac85d9d76acde5034a416c6e62748d5260728468f709d8d96c29c18a47a610b9c64bd3e3b06bd3b1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bbk-amqp (1.0.0.82260)
4
+ bbk-amqp (1.0.0.92190)
5
5
  activesupport (~> 6.0)
6
6
  bbk-utils (> 1.0.1)
7
7
  bunny (>= 2.19.0)
@@ -63,7 +63,7 @@ GEM
63
63
  launchy (2.5.0)
64
64
  addressable (~> 2.7)
65
65
  minitest (5.15.0)
66
- oj (3.13.11)
66
+ oj (3.13.19)
67
67
  parser (3.0.3.2)
68
68
  ast (~> 2.4.1)
69
69
  path_expander (1.1.0)
@@ -45,6 +45,10 @@ module BBK
45
45
  consumer.nack(self, *args, error: error, **kwargs)
46
46
  end
47
47
 
48
+ def clone
49
+ self.class.new(consumer, delivery_info, properties, body)
50
+ end
51
+
48
52
  end
49
53
  end
50
54
  end
@@ -73,13 +73,9 @@ module BBK
73
73
  routing_key: routing_key,
74
74
  headers: message.headers,
75
75
  # user_id: client_name,
76
- **message.headers.select {|k| HEADER_PROP_FIELDS.include? k }.compact
76
+ **message.headers.select {|k| HEADER_PROP_FIELDS.include?(k.to_sym) }.compact
77
77
  }.merge(options).symbolize_keys
78
- properties[:user_id] = if (user_id = message.headers[:user_id]).present?
79
- user_id
80
- else
81
- properties[:headers][:user_id] = client_name
82
- end
78
+ properties[:user_id] = client_name if message.headers[:user_id].blank?
83
79
  send_message(exchange, routing_key, message.payload, properties)
84
80
  end
85
81
 
@@ -0,0 +1,41 @@
1
+ module BBK
2
+ module AMQP
3
+ module RejectionPolicies
4
+ class Republish
5
+
6
+ REPUBLISH_COUNTER_KEY = 'x-republish-count'.freeze
7
+
8
+ attr_reader :logger
9
+
10
+ def initialize(publisher, logger: BBK::Utils::Logger.default)
11
+ @publisher = publisher
12
+ @logger = ActiveSupport::TaggedLogging.new(logger).tagged(self.class.name)
13
+ end
14
+
15
+ def call(message, error)
16
+ if message.delivery_info[:redelivered] || message.headers.key?(REPUBLISH_COUNTER_KEY)
17
+ republish_message(message, error)
18
+ else
19
+ requeue_message(message, error)
20
+ end
21
+ end
22
+
23
+ def requeue_message(message, error)
24
+ logger.warn "Requeue message #{message.headers[:type]}[#{message.headers[:message_id]}] delivery tag: #{message.delivery_info[:delivery_tag].to_i}. Error: #{error.inspect}"
25
+ message.delivery_info[:channel].reject message.delivery_info[:delivery_tag], true
26
+ end
27
+
28
+ def republish_message(message, error)
29
+ logger.warn "Republish message #{message.headers[:type]}[#{message.headers[:message_id]}]. Error: #{error.inspect}"
30
+ msg = message.clone
31
+ msg.headers[REPUBLISH_COUNTER_KEY] = msg.headers.fetch(REPUBLISH_COUNTER_KEY, 0).to_i + 1
32
+ @publisher.publish_message(msg.delivery_info[:queue], msg, exchange: '').value!
33
+ message.ack
34
+ end
35
+
36
+
37
+ end
38
+ end
39
+ end
40
+ end
41
+
data/lib/bbk/amqp.rb CHANGED
@@ -15,6 +15,7 @@ require 'bbk/amqp/domains/exchange'
15
15
  require 'bbk/amqp/domains/by_block'
16
16
  require 'bbk/amqp/rejection_policies/reject'
17
17
  require 'bbk/amqp/rejection_policies/requeue'
18
+ require 'bbk/amqp/rejection_policies/republish'
18
19
  require_relative 'bunny_patch'
19
20
 
20
21
 
@@ -6,6 +6,7 @@ module BBK
6
6
  # def nack: (*untyped, ?error: untyped, **untyped) -> void
7
7
 
8
8
  def initialize: (BBK::App::Dispatcher::_Consumer, untyped delivery_info, Hash[String|Symbol, untyped] properties, String? body) -> void
9
+ def clone: -> Message
9
10
  end
10
11
  end
11
12
  end
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.82260
4
+ version: 1.0.0.92190
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-04-14 00:00:00.000000000 Z
11
+ date: 2022-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -212,6 +212,7 @@ files:
212
212
  - lib/bbk/amqp/message.rb
213
213
  - lib/bbk/amqp/publisher.rb
214
214
  - lib/bbk/amqp/rejection_policies/reject.rb
215
+ - lib/bbk/amqp/rejection_policies/republish.rb
215
216
  - lib/bbk/amqp/rejection_policies/requeue.rb
216
217
  - lib/bbk/amqp/route_info.rb
217
218
  - lib/bbk/amqp/spec.rb