bbk-amqp 1.0.0.109994 → 1.1.0.199380

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: 66f28db2e42bb159e20d67828581f8396cc93699d88729662b78943198e75c6e
4
- data.tar.gz: 8918688acd752ddf9201e12857ff1f4b66674b8ef8fabc105ab427d8401e19f6
3
+ metadata.gz: b795df145f589a12ff12bb34e6f22652edfdfa4223936b5b50126102a161706e
4
+ data.tar.gz: 7e7bc1ae16fcf85e170d6d80eac94c49f825ae2e068a8d0852844dbf3fada0ce
5
5
  SHA512:
6
- metadata.gz: dcedc95871cb1d6f51750321c4167f05b317d2edbba787f3607c03f70f9d16788b6cdb4cb50c7270af778c4233207abc8a0f800a00276116c0351d7d09102845
7
- data.tar.gz: 3a732dfba76916ae52b525120093cf31b6219e356ff0db5734d3e3fac3cdde374099e4171963139d6d8242adf0f86b6d94ae7b02beb04fe98a0c302255eefd3c
6
+ metadata.gz: e44e7227e9d00acf3d163fd7f8c47c18582cd0874782b48ebe5a3a1401c67090e9e50aa5a297bae3485ed0ab0ce139b5cdc22fba890892e8ce4efcee838f5911
7
+ data.tar.gz: 7debad965b8ed99fc1a97ca029566a3230952317ba7b92c989edf7053eeb847f753c7e49b323c20703b3ea9818ded004f839a490a2cec7cf26125d43736a2848
data/Gemfile CHANGED
@@ -4,4 +4,3 @@ source 'https://rubygems.org'
4
4
 
5
5
  # Specify your gem's dependencies in bbk-amqp.gemspec
6
6
  gemspec
7
-
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bbk-amqp (1.0.0.109994)
4
+ bbk-amqp (1.1.0.199380)
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.23)
66
+ oj (3.16.1)
67
67
  parser (3.0.3.2)
68
68
  ast (~> 2.4.1)
69
69
  path_expander (1.1.0)
@@ -105,7 +105,7 @@ GEM
105
105
  virtus (~> 1.0)
106
106
  russian (0.6.0)
107
107
  i18n (>= 0.5.0)
108
- set (1.0.2)
108
+ set (1.0.3)
109
109
  sexp_processor (4.16.0)
110
110
  simplecov (0.21.2)
111
111
  docile (~> 1.1)
@@ -6,6 +6,7 @@ module BBK
6
6
  class Consumer
7
7
 
8
8
  attr_reader :connection, :queue_name, :queue, :rejection_policy, :options, :logger
9
+ attr_accessor :publisher
9
10
 
10
11
  DEFAULT_OPTIONS = {
11
12
  consumer_pool_size: 3,
@@ -17,10 +18,11 @@ module BBK
17
18
 
18
19
  PROTOCOLS = %w[mq amqp amqps].freeze
19
20
 
20
- def initialize(connection, queue_name: nil, **options)
21
+ def initialize(connection, queue_name: nil, publisher: nil, **options)
21
22
  @connection = connection
22
23
  @channel = options.delete(:channel)
23
24
  @queue = options.delete(:queue)
25
+ @publisher = publisher
24
26
 
25
27
  if @queue.nil? && queue_name.nil?
26
28
  raise ArgumentError.new('queue_name or queue must be provided!')
@@ -79,10 +81,20 @@ module BBK
79
81
  # [] - для работы тестов. В реальности вернется объект VersionedDeliveryTag у
80
82
  # которого to_i (вызывается внутри channel.ack) вернет фактическоe число
81
83
  # logger.debug "Ack message #{incoming.headers[:type]}[#{incoming.headers[:message_id]}] on channel: #{incoming.delivery_info[:channel]&.id}[#{incoming.delivery_info[:channel]&.object_id}] delivery tag: #{incoming.delivery_info[:delivery_tag].to_i}"
84
+ send_answer(incoming, answer) unless answer.nil?
82
85
  logger.debug "Ack message #{incoming.headers[:type]}[#{incoming.headers[:message_id]}] delivery tag: #{incoming.delivery_info[:delivery_tag].to_i}"
83
86
  incoming.delivery_info[:channel].ack incoming.delivery_info[:delivery_tag]
84
87
  end
85
88
 
89
+ protected def send_answer(incoming, answer)
90
+ if publisher.nil?
91
+ logger.error "Can't answer message: empty publisher"
92
+ raise "Publisher not configured in consumer #{self.inspect}"
93
+ end
94
+ logger.debug "Send answer message for incoming(message_id=#{incoming.message_id}) to #{answer.route}"
95
+ publisher.publish(answer).value!
96
+ end
97
+
86
98
  # Nack incoming message
87
99
  # @param incoming [BBK::AMQP::Message] nack procesing message
88
100
  def nack(incoming, *args, error: nil, **_kwargs)
@@ -17,7 +17,7 @@ module BBK
17
17
  protocols: consumer.protocols,
18
18
  queue: amqp_consumer&.queue_name
19
19
  )
20
- @headers = @properties.except(:headers).merge(properties[:headers]).with_indifferent_access
20
+ @headers = @properties.except(:headers).merge(properties[:headers].presence || {}).with_indifferent_access
21
21
  @payload = begin
22
22
  Oj.load(body).with_indifferent_access
23
23
  rescue StandardError
@@ -120,8 +120,7 @@ module BBK
120
120
  end
121
121
 
122
122
  def on_return(exchange, basic_return, properties, body)
123
- args = { exchange: exchange, basic_return: basic_return, properties: properties,
124
- body: body }
123
+ args = { exchange: exchange, basic_return: basic_return, properties: properties, body: body }
125
124
  message_id = properties[:message_id]
126
125
  logger.info "Message with message_id #{message_id} returned #{basic_return.inspect}"
127
126
  ack_id, = ack_map.each_pair.find {|_, msg_id| msg_id == message_id }
@@ -3,7 +3,7 @@
3
3
  module BBK
4
4
  module AMQP
5
5
 
6
- VERSION = '1.0.0'
6
+ VERSION = '1.1.0'
7
7
 
8
8
  end
9
9
  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.109994
4
+ version: 1.1.0.199380
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-18 00:00:00.000000000 Z
11
+ date: 2023-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -247,7 +247,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
247
247
  - !ruby/object:Gem::Version
248
248
  version: '0'
249
249
  requirements: []
250
- rubygems_version: 3.2.32
250
+ rubygems_version: 3.2.33
251
251
  signing_key:
252
252
  specification_version: 4
253
253
  summary: AMQP interaction classes for BBK stack