railway-ipc 1.0.1 → 1.1.0

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: 6b0a9b840874946f0f7e80b0221e3df161eed5ce0926299356856cb5b81f76db
4
- data.tar.gz: 252e1f3e84801e50cfccc47d6674c985a690e514cd2732b62c5f6cbbef71f0fc
3
+ metadata.gz: f2a31b80fc9d4f13598bdc2fbd14c84c78360bd4adeb588bb63b3bb20c33a2de
4
+ data.tar.gz: 2bfef85b0fbe56b0d66df365f8ffa5b7913b188658edbb63484aaa0138dfa6ba
5
5
  SHA512:
6
- metadata.gz: 69cde1dbbfcabb1ed5f3a27ace4a126f7cf231096aa8b8761c6ac3f19f0c36a4a79183a44140367117eab13f01e1507e53ef9a484abb89510df17ff040395407
7
- data.tar.gz: a2a85998d976faa746820474bb9e5597964bb92f379b95b7b55cc5936a72af532d3b5321d3228194f4209dbdab3b76dc430dbd2d357df33e9929ff3748465b6a
6
+ metadata.gz: a27c830370df223add103179c9e8b60d5259abbb5b21b664f0b2642d96e5736926325c07e271b08822401c312ef532ec8a6f3c03dba30ce5a637edcbbba1ed12
7
+ data.tar.gz: 555cb81425239fba2c5752e238bd541db554f48eb7d46d1336122d730781e40fdd0b339a8266a49a42ace8b73909d7a26f145b9e3ea5d9602fbfcefb9db1a022
@@ -10,6 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
10
10
  ### Removed
11
11
  ### Fixed
12
12
 
13
+ ## [1.1.0] - 2020-08-07
14
+ ### Changed
15
+ * allow multiple consumers to handle the same message
16
+ * consumed messages table requires its own primary key due to ActiveRecord not having support for composite primary keys
17
+
13
18
  ## [1.0.1] - 2020-07-23
14
19
  ### Fixed
15
20
  * Fix publisher connection by using default connection if one isn't provided
@@ -38,6 +43,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
38
43
  ### Added
39
44
  - Correlation ID and message UUID are auto generated for messages for IDs are not passed in [#23](https://github.com/learn-co/railway_ipc_gem/pull/23)
40
45
 
41
- [Unreleased]: https://github.com/learn-co/railway_ipc_gem/compare/v1.0.0...HEAD
46
+ [Unreleased]: https://github.com/learn-co/railway_ipc_gem/compare/v1.1.0...HEAD
47
+ [1.1.0]: https://github.com/learn-co/railway_ipc_gem/compare/v1.0.1...v1.1.0
48
+ [1.0.1]: https://github.com/learn-co/railway_ipc_gem/compare/v1.0.0...v1.0.1
42
49
  [1.0.0]: https://github.com/learn-co/railway_ipc_gem/compare/v0.1.7...v1.0.0
43
50
  [0.1.7]: https://github.com/learn-co/railway_ipc_gem/releases/tag/v0.1.7
@@ -1,10 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'railway_ipc/consumer/consumer_response_handlers'
4
-
5
3
  module RailwayIpc
6
4
  class Consumer
7
5
  include Sneakers::Worker
6
+ def self.inherited(base)
7
+ base.instance_eval do
8
+ def handlers
9
+ @handlers ||= RailwayIpc::HandlerStore.new
10
+ end
11
+ end
12
+ end
8
13
 
9
14
  def self.listen_to(queue:, exchange:)
10
15
  from_queue queue,
@@ -15,11 +20,15 @@ module RailwayIpc
15
20
  end
16
21
 
17
22
  def self.handle(message_type, with:)
18
- ConsumerResponseHandlers.instance.register(message: message_type, handler: with)
23
+ handlers.register(message: message_type, handler: with)
24
+ end
25
+
26
+ def handlers
27
+ self.class.handlers
19
28
  end
20
29
 
21
30
  def registered_handlers
22
- ConsumerResponseHandlers.instance.registered
31
+ handlers.registered
23
32
  end
24
33
 
25
34
  def queue_name
@@ -45,7 +54,7 @@ module RailwayIpc
45
54
  end
46
55
 
47
56
  def get_handler(type)
48
- manifest = ConsumerResponseHandlers.instance.get(type)
57
+ manifest = handlers.get(type)
49
58
  manifest ? manifest.handler.new : nil
50
59
  end
51
60
  end
@@ -86,11 +86,10 @@ module RailwayIpc
86
86
  end
87
87
 
88
88
  def find_or_create_consumed_message
89
- RailwayIpc::ConsumedMessage.find_by(uuid: incoming_message.uuid) ||
89
+ RailwayIpc::ConsumedMessage.find_by(uuid: incoming_message.uuid, queue: consumer.queue_name) ||
90
90
  RailwayIpc::ConsumedMessage.create_processing(consumer, incoming_message)
91
91
  end
92
92
 
93
- # rubocop:disable Metrics/AbcSize
94
93
  def classify_message
95
94
  if incoming_message.decoded.is_a?(RailwayIpc::Messages::Unknown)
96
95
  UnknownMessageJob.new(incoming_message, logger)
@@ -100,6 +99,5 @@ module RailwayIpc
100
99
  IgnoredMessageJob.new(incoming_message, logger)
101
100
  end
102
101
  end
103
- # rubocop:enable Metrics/AbcSize
104
102
  end
105
103
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'railway_ipc/handler_manifest'
4
3
  module RailwayIpc
4
+ HandlerManifest = Struct.new(:message, :handler)
5
5
  class HandlerStore
6
6
  attr_reader :handler_map
7
7
 
@@ -14,7 +14,7 @@ module RailwayIpc
14
14
  end
15
15
 
16
16
  def register(message:, handler:)
17
- handler_map[message.to_s] = HandlerManifest.new(message: message, handler: handler)
17
+ handler_map[message.to_s] = HandlerManifest.new(message, handler)
18
18
  end
19
19
 
20
20
  def get(response_message)
@@ -19,7 +19,6 @@ module RailwayIpc
19
19
  attr_reader :decoded_message
20
20
 
21
21
  self.table_name = 'railway_ipc_consumed_messages'
22
- self.primary_key = 'uuid'
23
22
 
24
23
  validates :uuid, :status, presence: true
25
24
  validates :status, inclusion: { in: VALID_STATUSES }
@@ -56,7 +56,6 @@ module RailwayIpc
56
56
  # rubocop:enable Metrics/AbcSize
57
57
  # rubocop:enable Metrics/MethodLength
58
58
 
59
- # rubocop:disable Metrics/AbcSize
60
59
  def handle_request(payload)
61
60
  response = work(payload)
62
61
  rescue StandardError => e
@@ -69,7 +68,6 @@ module RailwayIpc
69
68
  )
70
69
  end
71
70
  end
72
- # rubocop:enable Metrics/AbcSize
73
71
 
74
72
  private
75
73
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailwayIpc
4
- VERSION = '1.0.1'
4
+ VERSION = '1.1.0'
5
5
  end
@@ -2,20 +2,20 @@
2
2
 
3
3
  class AddRailwayIpcConsumedMessages < ActiveRecord::Migration
4
4
  def change
5
- create_table :railway_ipc_consumed_messages, id: false do |t|
5
+ create_table :railway_ipc_consumed_messages do |t|
6
6
  t.uuid :uuid, null: false
7
7
  t.string :message_type
8
8
  t.uuid :user_uuid
9
9
  t.uuid :correlation_id
10
10
  t.text :encoded_message
11
11
  t.string :status, null: false
12
- t.string :queue
12
+ t.string :queue, null: false
13
13
  t.string :exchange
14
14
 
15
15
  t.datetime :updated_at
16
16
  t.datetime :inserted_at
17
17
  end
18
18
 
19
- add_index :railway_ipc_consumed_messages, :uuid, unique: true
19
+ add_index :railway_ipc_consumed_messages, %i[uuid queue], unique: true
20
20
  end
21
21
  end
@@ -9,6 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.version = RailwayIpc::VERSION
10
10
  spec.authors = ''
11
11
  spec.email = ''
12
+ spec.required_ruby_version = '>= 2.5'
12
13
 
13
14
  spec.summary = 'IPC components for Rails'
14
15
  spec.description = 'IPC components for Rails'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railway-ipc
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-23 00:00:00.000000000 Z
11
+ date: 2020-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -213,7 +213,7 @@ extensions: []
213
213
  extra_rdoc_files: []
214
214
  files:
215
215
  - ".gitignore"
216
- - CHANGELOG.MD
216
+ - CHANGELOG.md
217
217
  - CODE_OF_CONDUCT.md
218
218
  - Gemfile
219
219
  - LICENSE.txt
@@ -226,11 +226,9 @@ files:
226
226
  - lib/railway_ipc.rb
227
227
  - lib/railway_ipc/Rakefile
228
228
  - lib/railway_ipc/consumer/consumer.rb
229
- - lib/railway_ipc/consumer/consumer_response_handlers.rb
230
229
  - lib/railway_ipc/consumer/process_incoming_message.rb
231
230
  - lib/railway_ipc/errors.rb
232
231
  - lib/railway_ipc/handler.rb
233
- - lib/railway_ipc/handler_manifest.rb
234
232
  - lib/railway_ipc/handler_store.rb
235
233
  - lib/railway_ipc/incoming_message.rb
236
234
  - lib/railway_ipc/logger.rb
@@ -265,7 +263,7 @@ licenses:
265
263
  - MIT
266
264
  metadata:
267
265
  allowed_push_host: https://rubygems.org/
268
- post_install_message:
266
+ post_install_message:
269
267
  rdoc_options: []
270
268
  require_paths:
271
269
  - lib
@@ -273,16 +271,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
273
271
  requirements:
274
272
  - - ">="
275
273
  - !ruby/object:Gem::Version
276
- version: '0'
274
+ version: '2.5'
277
275
  required_rubygems_version: !ruby/object:Gem::Requirement
278
276
  requirements:
279
277
  - - ">="
280
278
  - !ruby/object:Gem::Version
281
279
  version: '0'
282
280
  requirements: []
283
- rubyforge_project:
281
+ rubyforge_project:
284
282
  rubygems_version: 2.7.6
285
- signing_key:
283
+ signing_key:
286
284
  specification_version: 4
287
285
  summary: IPC components for Rails
288
286
  test_files: []
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'railway_ipc/handler_store'
4
- module RailwayIpc
5
- class ConsumerResponseHandlers
6
- include Singleton
7
- extend Forwardable
8
- def_delegators :handler_store, :registered, :register, :get
9
-
10
- private
11
-
12
- def handler_store
13
- @handler_store ||= RailwayIpc::HandlerStore.new
14
- end
15
- end
16
- end
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module RailwayIpc
4
- class HandlerManifest
5
- attr_reader :message, :handler
6
-
7
- def initialize(message:, handler:)
8
- @message = message
9
- @handler = handler
10
- end
11
- end
12
- end