bbk-amqp 1.0.0.82273 → 1.0.0.93643

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: 9bdb4acc4df0ff518a20e9ffea4c4f17728d32116f698d5f688e54932c57a8a1
4
- data.tar.gz: bab128573b4283b440c703883d3b3c37a7964411d85ac0462ae2b2f7d0fa5fb6
3
+ metadata.gz: de0feac4448e84adfdaef342e83e39cd0e0055d68d62dae857e7b003ae77ab0c
4
+ data.tar.gz: b5319839c4b9cc6869e7ba639451d65e14449bc6b34a8982a37f62a121274898
5
5
  SHA512:
6
- metadata.gz: 69fdbf711cd3a6624c797fe7517af3fbca9ed4ac9eba0faabe8556dfd74d8db72b92975a9da3299a3b63586f040256e99c97a9dff10782b354f5b2df559d8271
7
- data.tar.gz: faa15d700ba3147c593584aa83a8e3e020074da41afd1d8e1d01f228ca8dc0b83c07ba43f1512d1b24948df0c8fd4eea384b584875f40e7fae699ff11a5cc532
6
+ metadata.gz: 6c844782733ee4612b2aa6f75714d6965c8a6ac71f917b40abd8f6b83fa8cda762357dc1a0367facb8a55e336be9d31ed1e5fc561a5c232ddc7a926c1af69cdf
7
+ data.tar.gz: 247d5f7e190c3e946a5d31c170ac50c9bc2ff199d3a93a680a22d1aa7b665e38724f25f617c55fa123ae901f254c1e47f65a525971155c0a7da851e7b989d26f
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bbk-amqp (1.0.0.82273)
5
- activesupport (~> 6.0)
4
+ bbk-amqp (1.0.0.93643)
5
+ activesupport (>= 6.0)
6
6
  bbk-utils (> 1.0.1)
7
7
  bunny (>= 2.19.0)
8
8
  oj
@@ -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.20)
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,7 +73,7 @@ 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
78
  properties[:user_id] = client_name if message.headers[:user_id].blank?
79
79
  send_message(exchange, routing_key, message.payload, properties)
@@ -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,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbk-amqp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.82273
4
+ version: 1.0.0.93643
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-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '6.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '6.0'
27
27
  - !ruby/object:Gem::Dependency
@@ -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