bbk-app 1.0.0.152254 → 1.1.0.199383

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: 46d513493369b485e14db4e4ffcef827a409635d13e125dc6df66096b40993b8
4
- data.tar.gz: a24c4866933af57383e6ecd26730a6d52f0eda798398fbe10846fd854c0d5fe0
3
+ metadata.gz: cfb0384af4545b59b59a7de1f309e71e895bf2af47ce0526bcf0265b54606c60
4
+ data.tar.gz: 7fb2b293747d66a4d818bacf32a8fb72f5c48e48f7937d1931e4c2e73472cdc1
5
5
  SHA512:
6
- metadata.gz: 735ad0718af3db41205a5d2145282121d69d1891610160830f5f10a72986a334e843cebc96c115474cdb59ae8dd1338503749ab53ec4f7e138f7a78c777f6bb4
7
- data.tar.gz: 65b53f997cef141a0f7e281f776a18bc6bb258b5c0cdf9797c25280b67bec584adbb6fe53ede7092a6245a50b6979429aabdad0bdcb000f4619972df3fccb72a
6
+ metadata.gz: 17de92ea6e1492d94b66ad4af0efa83dc8ea43f4d3591250f39ae379323978e33da4541093b0d89451af71bb4e3bdfe820a50d30ebf938ad6bfc37ac07b679ca
7
+ data.tar.gz: '080cff24d3c3521d4c563433e001f6945571eb678849c2549ccc4a23148bd196e1f45164081e3a9c7dc295890b2552f5c960fb200cc3678fe797df11f352eff6'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bbk-app (1.0.0.152254)
4
+ bbk-app (1.1.0.199383)
5
5
  activesupport
6
6
  bbk-utils (> 1.0.1)
7
7
  timeouter
@@ -122,7 +122,7 @@ GEM
122
122
  virtus (~> 1.0)
123
123
  russian (0.6.0)
124
124
  i18n (>= 0.5.0)
125
- set (1.0.2)
125
+ set (1.0.3)
126
126
  sexp_processor (4.16.0)
127
127
  simplecov (0.21.2)
128
128
  docile (~> 1.1)
@@ -10,6 +10,8 @@ require 'bbk/utils/proxy_logger'
10
10
  module BBK
11
11
  module App
12
12
 
13
+ class InvalidAnswersMessagesCountError < StandardError; end
14
+
13
15
  class SimplePoolFactory
14
16
 
15
17
  def self.call(pool_size, queue_size)
@@ -32,7 +34,8 @@ module BBK
32
34
  attr_accessor :force_quit
33
35
  attr_reader :consumers, :publishers, :observer, :middlewares, :logger
34
36
 
35
- ANSWER_DOMAIN = 'answer'
37
+ ANSWER_DOMAIN = 'answer'.freeze
38
+ DEFAULT_PROTOCOL = 'default'.freeze
36
39
 
37
40
  def initialize(observer, pool_size: 3, logger: BBK::App.logger, pool_factory: SimplePoolFactory, stream_strategy: QueueStreamStrategy)
38
41
  @observer = observer
@@ -52,9 +55,20 @@ module BBK
52
55
  end
53
56
 
54
57
  def register_publisher(publisher)
58
+ raise "Publisher support #{DEFAULT_PROTOCOL}" if publisher.protocols.include?(DEFAULT_PROTOCOL)
55
59
  publishers << publisher
56
60
  end
57
61
 
62
+ # set default publisher for results with empty scheme or DEFAULT_PROTOCOL scheme
63
+ def default_publisher=(publisher)
64
+ @default_publisher = publisher
65
+ end
66
+
67
+ # get default publisher
68
+ def default_publisher
69
+ @default_publisher || (publishers.size == 1 ? publishers.first : nil)
70
+ end
71
+
58
72
  def register_middleware(middleware)
59
73
  middlewares << middleware
60
74
  end
@@ -122,18 +136,19 @@ module BBK
122
136
  end
123
137
  end
124
138
 
125
- protected
139
+ # process one message and sending existed results messages
140
+ def process(message)
141
+ results = execute_message(message)
142
+ logger.debug "There are #{results.count} results to send from #{message.headers[:message_id]}..."
143
+ send_results(message, results).value
144
+ rescue StandardError => e
145
+ logger.error "Failed processing message: #{e.inspect}"
146
+ ActiveSupport::Notifications.instrument 'dispatcher.exception', msg: message, exception: e
147
+ message.nack(error: e)
148
+ close if force_quit
149
+ end
126
150
 
127
- def process(message)
128
- results = execute_message(message)
129
- logger.debug "There are #{results.count} results to send from #{message.headers[:message_id]}..."
130
- send_results(message, results).value
131
- rescue StandardError => e
132
- logger.error "Failed processing message: #{e.inspect}"
133
- ActiveSupport::Notifications.instrument 'dispatcher.exception', msg: message, exception: e
134
- message.nack(error: e)
135
- close if force_quit
136
- end
151
+ protected
137
152
 
138
153
  def process_message(message)
139
154
  matched, processor = find_processor(message)
@@ -176,8 +191,12 @@ module BBK
176
191
  def send_results(incoming, results)
177
192
  message_id = incoming.headers[:message_id]
178
193
 
179
- answer = results.find {|msg| msg.route.domain == ANSWER_DOMAIN }
180
- Concurrent::Promises.zip_futures(*results.map do |result|
194
+ answers, sended_messages = results.partition { _1.route.domain == ANSWER_DOMAIN }
195
+ # allowed only one answer message
196
+ raise InvalidAnswersMessagesCountError.new("Get #{asnwers.size} on processing message with id=#{message_id}") if answers.size > 1
197
+
198
+ answer = answers.first
199
+ Concurrent::Promises.zip_futures(*sended_messages.map do |result|
181
200
  publish_result(result)
182
201
  end).then do |_successes|
183
202
  incoming.ack(answer: answer)
@@ -203,6 +222,10 @@ module BBK
203
222
  route = result.route
204
223
  logger.debug "Publish result to #{route} ..."
205
224
  publisher = publishers.find {|pub| pub.protocols.include?(route.scheme) }
225
+ if route.scheme.nil? || route.scheme == DEFAULT_PROTOCOL
226
+ logger.debug "Use default publisher for result with route=#{route}"
227
+ publisher = default_publisher
228
+ end
206
229
  raise "Not found publisher for scheme #{route.scheme}" if publisher.nil?
207
230
 
208
231
  # return Concurrent::Promises.resolvable_future
@@ -1,7 +1,7 @@
1
1
  module BBK
2
2
  module App
3
3
 
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
 
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbk-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.152254
4
+ version: 1.1.0.199383
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samoilenko Yuri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-15 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
@@ -320,7 +320,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
320
320
  - !ruby/object:Gem::Version
321
321
  version: '0'
322
322
  requirements: []
323
- rubygems_version: 3.2.32
323
+ rubygems_version: 3.2.33
324
324
  signing_key:
325
325
  specification_version: 4
326
326
  summary: Classes for building services based on BBK stack