railway-ipc 1.0.1 → 2.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b0a9b840874946f0f7e80b0221e3df161eed5ce0926299356856cb5b81f76db
4
- data.tar.gz: 252e1f3e84801e50cfccc47d6674c985a690e514cd2732b62c5f6cbbef71f0fc
3
+ metadata.gz: 444dfeb8a9729ca23276ce6f4a899589a646c93d3671fb517ab81d0fdc85958e
4
+ data.tar.gz: 9ede7408f2a428cf3345ef3b8aa684c6aa3fe43a6d460ef7eb6866a99f46fe71
5
5
  SHA512:
6
- metadata.gz: 69cde1dbbfcabb1ed5f3a27ace4a126f7cf231096aa8b8761c6ac3f19f0c36a4a79183a44140367117eab13f01e1507e53ef9a484abb89510df17ff040395407
7
- data.tar.gz: a2a85998d976faa746820474bb9e5597964bb92f379b95b7b55cc5936a72af532d3b5321d3228194f4209dbdab3b76dc430dbd2d357df33e9929ff3748465b6a
6
+ metadata.gz: d15afcbeec8272d7e9b3c9e589f7ed88ffc8fb50fbf370cbaabf596a753e435bd7c67980668c7ce27d13b1b4dff7adf2b4b11f3b7c2f28ec224295bfc7f8ec69
7
+ data.tar.gz: 1d39cf3abce42366a096a83d15f8a287e32fbb7ef239fd17f04707ef0eed9fc7c5e3c06e129b4e4345871def82914a740fc6cab5039cc5d2934886342207aa67
@@ -0,0 +1,77 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+ ### Added
9
+ ### Changed
10
+ ### Removed
11
+ ### Fixed
12
+
13
+ ## [2.0.3] - 2020-09-02
14
+ ### Fixed
15
+ * Fix RPC server. RPC servers need to conform to the Sneaker worker API (i.e. their initializers need to be able to accept queue name / pool and they require a `stop` method.
16
+
17
+ ## [2.0.2] - 2020-08-27
18
+ ### Changed
19
+ * RPC `RailwayIpc::Client` does not need to log the queue name.
20
+
21
+ ## [2.0.1] - 2020-08-24
22
+ ### Fixed
23
+ * `RailwayIpc::Logger` now handles block syntax (i.e. `logger.info { 'my message' }`) correctly.
24
+
25
+ ## [2.0.0] - 2020-08-20
26
+ ### Added
27
+ * Several additions to internal logging:
28
+ - Log messages now include a `feature` key. This can be used by logging aggregator tools to group log messages across different systems that use the gem. If one isn't provided a default value of `railway_ipc` is used.
29
+ - Protobufs are logged as a sub-hash which contains both the protobuf type and payload.
30
+ - Exchange and queue names are logged where applicable.
31
+ - The internal Bunny connection now uses the `RailwayIpc::Logger` instead of a generic `Logger`.
32
+
33
+ ### Changed
34
+ * *Breaking Change* `RailwayIpc.configure` now takes `device`, `level`, and `formatter` instead of a complete `Logger` instance. The instance is now managed internally by Railway. This is a breaking change to the `RailwayIpc.configure` API, clients will need to be updated to use the new syntax.
35
+
36
+ ## [1.1.0] - 2020-08-07
37
+ ### Changed
38
+ * allow multiple consumers to handle the same message
39
+ * consumed messages table requires its own primary key due to ActiveRecord not having support for composite primary keys
40
+
41
+ ## [1.0.1] - 2020-07-23
42
+ ### Fixed
43
+ * Fix publisher connection by using default connection if one isn't provided
44
+
45
+ ## [1.0.0] - 2020-07-20
46
+ ### Added
47
+ * CircleCI build that runs the specs
48
+ * Rubocop (also ran by CircleCI)
49
+ * New error types for incoming messages
50
+ * RailwayIpc::Messages::Unknown protobuf
51
+
52
+ ### Changed
53
+ * Refactored worker to use ProcessIncomingMessage and IncomingMessage abstractions
54
+ * Moved decoding logic from ConsumedMessage to IncomingMessage
55
+ * Removed STATUSES constant from ConsumedMessage
56
+ * Publisher is no longer a Singleton; kept a Singleton version of the Publisher for backwards compatibility that gives a "deprecated" warning
57
+
58
+ ### Removed
59
+ * Removed `BaseMessage` protobuf
60
+ * NullMessage and NullHandler were removed
61
+
62
+ ### Fixed
63
+ * Fixed all Rubocop warnings and errors
64
+
65
+ ## [0.1.7] - 2020-06-29
66
+ ### Added
67
+ - 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)
68
+
69
+ [Unreleased]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.3...HEAD
70
+ [2.0.3]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.2...v2.0.3
71
+ [2.0.2]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.1...v2.0.2
72
+ [2.0.1]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.0...v2.0.1
73
+ [2.0.0]: https://github.com/learn-co/railway_ipc_gem/compare/v1.1.0...v2.0.0
74
+ [1.1.0]: https://github.com/learn-co/railway_ipc_gem/compare/v1.0.1...v1.1.0
75
+ [1.0.1]: https://github.com/learn-co/railway_ipc_gem/compare/v1.0.0...v1.0.1
76
+ [1.0.0]: https://github.com/learn-co/railway_ipc_gem/compare/v0.1.7...v1.0.0
77
+ [0.1.7]: https://github.com/learn-co/railway_ipc_gem/releases/tag/v0.1.7
data/README.md CHANGED
@@ -19,7 +19,7 @@ And then execute:
19
19
  ```ruby
20
20
  # config/initializers/railway_ipc.rb
21
21
 
22
- RailwayIpc.configure(logger: Rails.logger)
22
+ RailwayIpc.configure(STDOUT, Logger::INFO, MyFormatter)
23
23
  ```
24
24
 
25
25
  * Load the rake tasks in your Rakefile
@@ -29,16 +29,12 @@ module RailwayIpc
29
29
  Rake::Task['sneakers:run'].invoke
30
30
  end
31
31
 
32
- def self.configure(logger: ::Logger.new(STDOUT))
33
- @logger = RailwayIpc::Logger.new(logger)
32
+ def self.configure(log_device=STDOUT, level=::Logger::INFO, log_formatter=nil)
33
+ @logger = RailwayIpc::Logger.new(log_device, level, log_formatter)
34
34
  end
35
35
 
36
36
  def self.logger
37
- @logger || RailwayIpc::Logger.new(::Logger.new(STDOUT))
38
- end
39
-
40
- def self.bunny_logger
41
- logger.logger
37
+ @logger || RailwayIpc::Logger.new(STDOUT)
42
38
  end
43
39
 
44
40
  def self.bunny_connection
@@ -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
@@ -35,17 +44,19 @@ module RailwayIpc
35
44
  RailwayIpc::ProcessIncomingMessage.call(self, message)
36
45
  ack!
37
46
  rescue StandardError => e
38
- RailwayIpc.logger.log_exception(
39
- feature: 'railway_consumer',
47
+ RailwayIpc.logger.error(
48
+ e.message,
49
+ feature: 'railway_ipc_consumer',
50
+ exchange: exchange_name,
51
+ queue: queue_name,
40
52
  error: e.class,
41
- error_message: e.message,
42
53
  payload: payload
43
54
  )
44
55
  raise e
45
56
  end
46
57
 
47
58
  def get_handler(type)
48
- manifest = ConsumerResponseHandlers.instance.get(type)
59
+ manifest = handlers.get(type)
49
60
  manifest ? manifest.handler.new : nil
50
61
  end
51
62
  end
@@ -16,8 +16,9 @@ module RailwayIpc
16
16
 
17
17
  def run
18
18
  logger.warn(
19
- incoming_message.decoded,
20
- "Ignoring unknown message of type '#{incoming_message.type}'"
19
+ "Ignoring unknown message of type '#{incoming_message.type}'",
20
+ feature: 'railway_ipc_consumer',
21
+ protobuf: { type: incoming_message.type, data: incoming_message.decoded }
21
22
  )
22
23
  end
23
24
  end
@@ -36,8 +37,9 @@ module RailwayIpc
36
37
 
37
38
  def run
38
39
  logger.warn(
39
- incoming_message.decoded,
40
- "Ignoring message, no registered handler for '#{incoming_message.type}'"
40
+ "Ignoring message, no registered handler for '#{incoming_message.type}'",
41
+ feature: 'railway_ipc_consumer',
42
+ protobuf: { type: incoming_message.type, data: incoming_message.decoded }
41
43
  )
42
44
  end
43
45
  end
@@ -81,16 +83,21 @@ module RailwayIpc
81
83
 
82
84
  def raise_message_invalid_error
83
85
  error = "Message is invalid: #{incoming_message.stringify_errors}."
84
- logger.error(incoming_message.decoded, error)
86
+ logger.error(
87
+ error,
88
+ feature: 'railway_ipc_consumer',
89
+ exchange: consumer.exchange_name,
90
+ queue: consumer.queue_name,
91
+ protobuf: { type: incoming_message.class, data: incoming_message.decoded }
92
+ )
85
93
  raise RailwayIpc::IncomingMessage::InvalidMessage.new(error)
86
94
  end
87
95
 
88
96
  def find_or_create_consumed_message
89
- RailwayIpc::ConsumedMessage.find_by(uuid: incoming_message.uuid) ||
97
+ RailwayIpc::ConsumedMessage.find_by(uuid: incoming_message.uuid, queue: consumer.queue_name) ||
90
98
  RailwayIpc::ConsumedMessage.create_processing(consumer, incoming_message)
91
99
  end
92
100
 
93
- # rubocop:disable Metrics/AbcSize
94
101
  def classify_message
95
102
  if incoming_message.decoded.is_a?(RailwayIpc::Messages::Unknown)
96
103
  UnknownMessageJob.new(incoming_message, logger)
@@ -100,6 +107,5 @@ module RailwayIpc
100
107
  IgnoredMessageJob.new(incoming_message, logger)
101
108
  end
102
109
  end
103
- # rubocop:enable Metrics/AbcSize
104
110
  end
105
111
  end
@@ -11,15 +11,27 @@ module RailwayIpc
11
11
  end
12
12
 
13
13
  def handle(message)
14
- RailwayIpc.logger.info(message, 'Handling message')
14
+ RailwayIpc.logger.info('Handling message', log_message_options(message))
15
15
  response = self.class.block.call(message)
16
16
  if response.success?
17
- RailwayIpc.logger.info(message, 'Successfully handled message')
17
+ RailwayIpc.logger.info('Successfully handled message', log_message_options(message))
18
18
  else
19
- RailwayIpc.logger.error(message, 'Failed to handle message')
19
+ RailwayIpc.logger.error('Failed to handle message', log_message_options(message))
20
20
  end
21
21
 
22
22
  response
23
23
  end
24
+
25
+ private
26
+
27
+ def log_message_options(message)
28
+ {
29
+ feature: 'railway_ipc_consumer',
30
+ protobuf: {
31
+ type: message.class.name,
32
+ data: message
33
+ }
34
+ }
35
+ end
24
36
  end
25
37
  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)
@@ -1,36 +1,53 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailwayIpc
4
+ # Custom logger that accepts a `device`, `level`, and `formatter`.
5
+ # `formatter` can be any object that responds to `call`; a
6
+ # `Logger::Formatter` is used if the argument is not provided.
7
+ #
8
+ # Here is an example formatter that uses `Oj` to format structured log
9
+ # messages:
10
+ #
11
+ # require 'oj'
12
+ # OjFormatter = proc do |severity, datetime, progname, data|
13
+ # data.merge!(
14
+ # name: progname,
15
+ # timestamp: datetime,
16
+ # severity: severity
17
+ # )
18
+ # Oj.dump(data, { mode: :compat, time_format: :xmlschema })
19
+ # end
20
+ #
21
+ # logger = RailwayIpc::Logger.new(STDOUT, Logger::INFO, OjFormatter)
22
+ #
4
23
  class Logger
5
- attr_reader :logger
6
-
7
- def initialize(logger)
8
- @logger = logger
9
- end
10
-
11
- def info(message, statement)
12
- logger.info("[#{message_header(message)}] #{statement}")
24
+ def initialize(device=STDOUT, level=::Logger::INFO, formatter=nil)
25
+ @logger = ::Logger.new(device)
26
+ @logger.level = level
27
+ @logger.formatter = formatter if formatter
13
28
  end
14
29
 
15
- def warn(message, statement)
16
- logger.warn("[#{message_header(message)}] #{statement}")
30
+ %w[fatal error warn info debug].each do |level|
31
+ define_method(level) do |message=nil, data={}, &block|
32
+ data.merge!(feature: 'railway_ipc') unless data.key?(:feature)
33
+ return logger.send(level, data.merge(message: message)) unless block
34
+
35
+ data = message.merge(data) if message&.is_a?(Hash)
36
+ data.merge!(message: block.call)
37
+
38
+ # This is for compatability w/ Ruby's Logger. Ruby's Logger class
39
+ # assumes that if both a `message` argument and a block are given,
40
+ # that the block contains the actual message. The `message` argument
41
+ # is assumed to be the `progname`.
42
+ #
43
+ # https://github.com/ruby/logger/blob/master/lib/logger.rb#L471
44
+ data.merge!(progname: message) if message&.is_a?(String)
45
+ logger.send(level, data)
46
+ end
17
47
  end
18
48
 
19
- def debug(message, statement)
20
- logger.debug("[#{message_header(message)}] #{statement}")
21
- end
49
+ private
22
50
 
23
- def error(message, statement)
24
- logger.error("[#{message_header(message)}] #{statement}")
25
- end
26
-
27
- def log_exception(exception)
28
- logger.error(exception)
29
- end
30
-
31
- def message_header(message)
32
- log_statement = "message type: #{message.class}, uuid: #{message.uuid}, correlation_id: #{message.correlation_id}"
33
- message.respond_to?(:user_uuid) ? "#{log_statement}, user_uuid: #{message.user_uuid}" : log_statement
34
- end
51
+ attr_reader :logger
35
52
  end
36
53
  end
@@ -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 }
@@ -21,16 +21,15 @@ module RailwayIpc
21
21
  end
22
22
 
23
23
  def publish(message, published_message_store=RailwayIpc::PublishedMessage)
24
- RailwayIpc.logger.logger.warn('DEPRECATED: Use new PublisherInstance class')
24
+ RailwayIpc.logger.warn('DEPRECATED: Use new PublisherInstance class', log_message_options)
25
25
  ensure_message_uuid(message)
26
26
  ensure_correlation_id(message)
27
- RailwayIpc.logger.info(message, 'Publishing message')
28
-
27
+ RailwayIpc.logger.info('Publishing message', log_message_options(message))
29
28
  result = super(RailwayIpc::Rabbitmq::Payload.encode(message))
30
29
  published_message_store.store_message(self.class.exchange_name, message)
31
30
  result
32
31
  rescue RailwayIpc::InvalidProtobuf => e
33
- RailwayIpc.logger.error(message, 'Invalid protobuf')
32
+ RailwayIpc.logger.error('Invalid protobuf', log_message_options(message))
34
33
  raise e
35
34
  end
36
35
 
@@ -45,6 +44,11 @@ module RailwayIpc
45
44
  message.correlation_id = SecureRandom.uuid if message.correlation_id.blank?
46
45
  message
47
46
  end
47
+
48
+ def log_message_options(message=nil)
49
+ options = { feature: 'railway_ipc_publisher', exchange: self.class.exchange_name }
50
+ message.nil? ? options : options.merge(protobuf: { type: message.class, data: message })
51
+ end
48
52
  end
49
53
  end
50
54
 
@@ -68,20 +72,33 @@ module RailwayIpc
68
72
  def publish(message)
69
73
  message.uuid = SecureRandom.uuid if message.uuid.blank?
70
74
  message.correlation_id = SecureRandom.uuid if message.correlation_id.blank?
71
- RailwayIpc.logger.info(message, 'Publishing message')
75
+ RailwayIpc.logger.info('Publishing message', log_message_options(message))
72
76
 
73
77
  stored_message = message_store.store_message(exchange_name, message)
74
78
  super(RailwayIpc::Rabbitmq::Payload.encode(message))
75
79
  rescue RailwayIpc::InvalidProtobuf => e
76
- RailwayIpc.logger.error(message, 'Invalid protobuf')
80
+ RailwayIpc.logger.error('Invalid protobuf', log_message_options(message))
77
81
  raise e
78
82
  rescue ActiveRecord::RecordInvalid => e
79
- RailwayIpc.logger.error(message, 'Failed to store outgoing message')
83
+ RailwayIpc.logger.error('Failed to store outgoing message', log_message_options(message))
80
84
  raise RailwayIpc::FailedToStoreOutgoingMessage.new(e)
81
85
  rescue StandardError => e
82
86
  stored_message&.destroy
83
87
  raise e
84
88
  end
85
89
  # rubocop:enable Metrics/AbcSize
90
+
91
+ private
92
+
93
+ def log_message_options(message)
94
+ {
95
+ feature: 'railway_ipc_publisher',
96
+ exchange: exchange_name,
97
+ protobuf: {
98
+ type: message.class,
99
+ data: message
100
+ }
101
+ }
102
+ end
86
103
  end
87
104
  end
@@ -28,7 +28,7 @@ module RailwayIpc
28
28
  port: settings[:port],
29
29
  vhost: vhost,
30
30
  automatic_recovery: false,
31
- logger: RailwayIpc.bunny_logger
31
+ logger: RailwayIpc.logger
32
32
  }.merge(options))
33
33
  end
34
34
 
@@ -11,7 +11,11 @@ module RailwayIpc
11
11
  end
12
12
 
13
13
  def respond(request)
14
- RailwayIpc.logger.info(request, 'Responding to request')
14
+ RailwayIpc.logger.info(
15
+ 'Responding to request',
16
+ protobuf: { type: request.class, data: request },
17
+ feature: 'railway_ipc_request'
18
+ )
15
19
  response = self.class.block.call(request)
16
20
  raise ResponseTypeError.new(response.class) unless response.is_a?(Google::Protobuf::MessageExts)
17
21
 
@@ -44,7 +44,12 @@ module RailwayIpc
44
44
  case decoded_payload.type
45
45
  when *registered_handlers
46
46
  @message = get_message_class(decoded_payload).decode(decoded_payload.message)
47
- RailwayIpc.logger.info(message, 'Handling response')
47
+ RailwayIpc.logger.info(
48
+ 'Handling response',
49
+ feature: 'railway_ipc_consumer',
50
+ exchange: self.class.exchange_name,
51
+ protobuf: { type: message.class, data: message }
52
+ )
48
53
  RailwayIpc::Response.new(message, success: true)
49
54
  else
50
55
  @message = LearnIpc::ErrorMessage.decode(decoded_payload.message)
@@ -78,10 +83,11 @@ module RailwayIpc
78
83
  private
79
84
 
80
85
  def log_exception(exception, payload)
81
- RailwayIpc.logger.log_exception(
82
- feature: 'railway_consumer',
86
+ RailwayIpc.logger.error(
87
+ exception.message,
88
+ feature: 'railway_ipc_consumer',
89
+ exchange: self.class.exchange_name,
83
90
  error: exception.class,
84
- error_message: exception.message,
85
91
  payload: decode_for_error(exception, payload)
86
92
  )
87
93
  end
@@ -99,7 +105,12 @@ module RailwayIpc
99
105
  end
100
106
 
101
107
  def publish_message
102
- RailwayIpc.logger.info(request_message, 'Sending request')
108
+ RailwayIpc.logger.info(
109
+ 'Sending request',
110
+ feature: 'railway_ipc_publisher',
111
+ exchange: self.class.exchange_name,
112
+ protobuf: { type: request_message.class, data: request_message }
113
+ )
103
114
  rabbit_connection.publish(RailwayIpc::Rabbitmq::Payload.encode(request_message), routing_key: '')
104
115
  end
105
116
 
@@ -14,7 +14,7 @@ module RailwayIpc
14
14
  RailwayIpc::RPC::ServerResponseHandlers.instance.register(handler: with, message: message_type)
15
15
  end
16
16
 
17
- def initialize(opts={ automatic_recovery: true }, rabbit_adapter: RailwayIpc::Rabbitmq::Adapter)
17
+ def initialize(_queue, _pool, opts={ automatic_recovery: true }, rabbit_adapter: RailwayIpc::Rabbitmq::Adapter)
18
18
  @rabbit_connection = rabbit_adapter.new(
19
19
  queue_name: self.class.queue_name,
20
20
  exchange_name: self.class.exchange_name,
@@ -31,6 +31,10 @@ module RailwayIpc
31
31
  subscribe_to_queue
32
32
  end
33
33
 
34
+ def stop
35
+ rabbit_connection.disconnect
36
+ end
37
+
34
38
  # rubocop:disable Metrics/AbcSize
35
39
  # rubocop:disable Metrics/MethodLength
36
40
  def work(payload)
@@ -45,10 +49,12 @@ module RailwayIpc
45
49
  raise RailwayIpc::UnhandledMessageError.new("#{self.class} does not know how to handle #{decoded_payload.type}")
46
50
  end
47
51
  rescue StandardError => e
48
- RailwayIpc.logger.log_exception(
49
- feature: 'railway_consumer',
52
+ RailwayIpc.logger.error(
53
+ e.message,
54
+ feature: 'railway_ipc_consumer',
55
+ exchange: self.class.exchange_name,
56
+ queue: self.class.queue_name,
50
57
  error: e.class,
51
- error_message: e.message,
52
58
  payload: payload
53
59
  )
54
60
  raise e
@@ -57,10 +63,18 @@ module RailwayIpc
57
63
  # rubocop:enable Metrics/MethodLength
58
64
 
59
65
  # rubocop:disable Metrics/AbcSize
66
+ # rubocop:disable Metrics/MethodLength
60
67
  def handle_request(payload)
61
68
  response = work(payload)
62
69
  rescue StandardError => e
63
- RailwayIpc.logger.error(message, "Error responding to message. Error: #{e.class}, #{e.message}")
70
+ RailwayIpc.logger.error(
71
+ 'Error responding to message.',
72
+ exception: e,
73
+ feature: 'railway_ipc_consumer',
74
+ exchange: self.class.exchange_name,
75
+ queue: self.class.queue_name,
76
+ protobuf: { type: message.class, data: message }
77
+ )
64
78
  response = self.class.rpc_error_adapter_class.error_message(e, message)
65
79
  ensure
66
80
  if response
@@ -70,6 +84,7 @@ module RailwayIpc
70
84
  end
71
85
  end
72
86
  # rubocop:enable Metrics/AbcSize
87
+ # rubocop:enable Metrics/MethodLength
73
88
 
74
89
  private
75
90
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailwayIpc
4
- VERSION = '1.0.1'
4
+ VERSION = '2.0.3'
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: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-23 00:00:00.000000000 Z
11
+ date: 2020-09-02 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
@@ -273,7 +271,7 @@ 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
  - - ">="
@@ -1,43 +0,0 @@
1
- # Changelog
2
- All notable changes to this project will be documented in this file.
3
-
4
- The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
- and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
-
7
- ## [Unreleased]
8
- ### Added
9
- ### Changed
10
- ### Removed
11
- ### Fixed
12
-
13
- ## [1.0.1] - 2020-07-23
14
- ### Fixed
15
- * Fix publisher connection by using default connection if one isn't provided
16
-
17
- ## [1.0.0] - 2020-07-20
18
- ### Added
19
- * CircleCI build that runs the specs
20
- * Rubocop (also ran by CircleCI)
21
- * New error types for incoming messages
22
- * RailwayIpc::Messages::Unknown protobuf
23
-
24
- ### Changed
25
- * Refactored worker to use ProcessIncomingMessage and IncomingMessage abstractions
26
- * Moved decoding logic from ConsumedMessage to IncomingMessage
27
- * Removed STATUSES constant from ConsumedMessage
28
- * Publisher is no longer a Singleton; kept a Singleton version of the Publisher for backwards compatibility that gives a "deprecated" warning
29
-
30
- ### Removed
31
- * Removed `BaseMessage` protobuf
32
- * NullMessage and NullHandler were removed
33
-
34
- ### Fixed
35
- * Fixed all Rubocop warnings and errors
36
-
37
- ## [0.1.7] - 2020-06-29
38
- ### Added
39
- - 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
-
41
- [Unreleased]: https://github.com/learn-co/railway_ipc_gem/compare/v1.0.0...HEAD
42
- [1.0.0]: https://github.com/learn-co/railway_ipc_gem/compare/v0.1.7...v1.0.0
43
- [0.1.7]: https://github.com/learn-co/railway_ipc_gem/releases/tag/v0.1.7
@@ -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