railway-ipc 1.0.0 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +72 -0
- data/README.md +1 -1
- data/lib/railway_ipc.rb +3 -7
- data/lib/railway_ipc/consumer/consumer.rb +19 -8
- data/lib/railway_ipc/consumer/process_incoming_message.rb +14 -8
- data/lib/railway_ipc/handler.rb +15 -3
- data/lib/railway_ipc/handler_store.rb +2 -2
- data/lib/railway_ipc/logger.rb +42 -25
- data/lib/railway_ipc/models/consumed_message.rb +0 -1
- data/lib/railway_ipc/publisher.rb +34 -11
- data/lib/railway_ipc/rabbitmq/adapter.rb +1 -1
- data/lib/railway_ipc/responder.rb +5 -1
- data/lib/railway_ipc/rpc/client/client.rb +16 -5
- data/lib/railway_ipc/rpc/server/server.rb +15 -4
- data/lib/railway_ipc/version.rb +1 -1
- data/priv/migrations/add_railway_ipc_consumed_messages.rb +3 -3
- data/railway_ipc.gemspec +1 -0
- metadata +4 -6
- data/CHANGELOG.MD +0 -39
- data/lib/railway_ipc/consumer/consumer_response_handlers.rb +0 -16
- data/lib/railway_ipc/handler_manifest.rb +0 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38510e51a7320246c8351c026b49b77a72c3886d96f39735749bb2d8b0c580e8
|
4
|
+
data.tar.gz: '06182d40648d84f3c1a421073fc566fae21c8d966f241602ab29d260aea74d8e'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95f03fe787853fa46d71adba1bb452cbd6f514bae0c25a9c068df148769ac6aa1f22237162bdbbc6c099cc4f81623086be76d8b53083661eddfd3427835be5ba
|
7
|
+
data.tar.gz: f8a5736baf4ca3d84c57896d30db7deefcd26068b3c56c108b5f673d9e62368fea48fb9c9004479e92282edcdf77e86c0523374966f4e627530a665c6fec8f6f
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,72 @@
|
|
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.2] - 2020-08-27
|
14
|
+
### Changed
|
15
|
+
* RPC `RailwayIpc::Client` does not need to log the queue name.
|
16
|
+
|
17
|
+
## [2.0.1] - 2020-08-24
|
18
|
+
### Fixed
|
19
|
+
* `RailwayIpc::Logger` now handles block syntax (i.e. `logger.info { 'my message' }`) correctly.
|
20
|
+
|
21
|
+
## [2.0.0] - 2020-08-20
|
22
|
+
### Added
|
23
|
+
* Several additions to internal logging:
|
24
|
+
- 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.
|
25
|
+
- Protobufs are logged as a sub-hash which contains both the protobuf type and payload.
|
26
|
+
- Exchange and queue names are logged where applicable.
|
27
|
+
- The internal Bunny connection now uses the `RailwayIpc::Logger` instead of a generic `Logger`.
|
28
|
+
|
29
|
+
### Changed
|
30
|
+
* *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.
|
31
|
+
|
32
|
+
## [1.1.0] - 2020-08-07
|
33
|
+
### Changed
|
34
|
+
* allow multiple consumers to handle the same message
|
35
|
+
* consumed messages table requires its own primary key due to ActiveRecord not having support for composite primary keys
|
36
|
+
|
37
|
+
## [1.0.1] - 2020-07-23
|
38
|
+
### Fixed
|
39
|
+
* Fix publisher connection by using default connection if one isn't provided
|
40
|
+
|
41
|
+
## [1.0.0] - 2020-07-20
|
42
|
+
### Added
|
43
|
+
* CircleCI build that runs the specs
|
44
|
+
* Rubocop (also ran by CircleCI)
|
45
|
+
* New error types for incoming messages
|
46
|
+
* RailwayIpc::Messages::Unknown protobuf
|
47
|
+
|
48
|
+
### Changed
|
49
|
+
* Refactored worker to use ProcessIncomingMessage and IncomingMessage abstractions
|
50
|
+
* Moved decoding logic from ConsumedMessage to IncomingMessage
|
51
|
+
* Removed STATUSES constant from ConsumedMessage
|
52
|
+
* Publisher is no longer a Singleton; kept a Singleton version of the Publisher for backwards compatibility that gives a "deprecated" warning
|
53
|
+
|
54
|
+
### Removed
|
55
|
+
* Removed `BaseMessage` protobuf
|
56
|
+
* NullMessage and NullHandler were removed
|
57
|
+
|
58
|
+
### Fixed
|
59
|
+
* Fixed all Rubocop warnings and errors
|
60
|
+
|
61
|
+
## [0.1.7] - 2020-06-29
|
62
|
+
### Added
|
63
|
+
- 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)
|
64
|
+
|
65
|
+
[Unreleased]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.2...HEAD
|
66
|
+
[2.0.2]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.1...v2.0.2
|
67
|
+
[2.0.1]: https://github.com/learn-co/railway_ipc_gem/compare/v2.0.0...v2.0.1
|
68
|
+
[2.0.0]: https://github.com/learn-co/railway_ipc_gem/compare/v1.1.0...v2.0.0
|
69
|
+
[1.1.0]: https://github.com/learn-co/railway_ipc_gem/compare/v1.0.1...v1.1.0
|
70
|
+
[1.0.1]: https://github.com/learn-co/railway_ipc_gem/compare/v1.0.0...v1.0.1
|
71
|
+
[1.0.0]: https://github.com/learn-co/railway_ipc_gem/compare/v0.1.7...v1.0.0
|
72
|
+
[0.1.7]: https://github.com/learn-co/railway_ipc_gem/releases/tag/v0.1.7
|
data/README.md
CHANGED
data/lib/railway_ipc.rb
CHANGED
@@ -29,16 +29,12 @@ module RailwayIpc
|
|
29
29
|
Rake::Task['sneakers:run'].invoke
|
30
30
|
end
|
31
31
|
|
32
|
-
def self.configure(
|
33
|
-
@logger = RailwayIpc::Logger.new(
|
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(
|
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
|
-
|
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
|
-
|
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.
|
39
|
-
|
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 =
|
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.
|
20
|
-
|
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.
|
40
|
-
|
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(
|
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
|
data/lib/railway_ipc/handler.rb
CHANGED
@@ -11,15 +11,27 @@ module RailwayIpc
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def handle(message)
|
14
|
-
RailwayIpc.logger.info(
|
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(
|
17
|
+
RailwayIpc.logger.info('Successfully handled message', log_message_options(message))
|
18
18
|
else
|
19
|
-
RailwayIpc.logger.error(
|
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
|
17
|
+
handler_map[message.to_s] = HandlerManifest.new(message, handler)
|
18
18
|
end
|
19
19
|
|
20
20
|
def get(response_message)
|
data/lib/railway_ipc/logger.rb
CHANGED
@@ -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
|
-
|
6
|
-
|
7
|
-
|
8
|
-
@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
|
-
|
16
|
-
|
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
|
-
|
20
|
-
logger.debug("[#{message_header(message)}] #{statement}")
|
21
|
-
end
|
49
|
+
private
|
22
50
|
|
23
|
-
|
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
|
@@ -21,16 +21,15 @@ module RailwayIpc
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def publish(message, published_message_store=RailwayIpc::PublishedMessage)
|
24
|
-
RailwayIpc.logger.
|
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(
|
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(
|
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
|
|
@@ -52,30 +56,49 @@ module RailwayIpc
|
|
52
56
|
class Publisher < Sneakers::Publisher
|
53
57
|
attr_reader :exchange_name, :message_store
|
54
58
|
|
55
|
-
def initialize(
|
56
|
-
@exchange_name = exchange_name
|
57
|
-
@message_store = message_store
|
58
|
-
|
59
|
+
def initialize(opts={})
|
60
|
+
@exchange_name = opts.fetch(:exchange_name)
|
61
|
+
@message_store = opts.fetch(:message_store, RailwayIpc::PublishedMessage)
|
62
|
+
connection = opts.fetch(:connection, nil)
|
63
|
+
options = {
|
64
|
+
exchange: exchange_name,
|
65
|
+
connection: connection,
|
66
|
+
exchange_type: :fanout
|
67
|
+
}.compact
|
68
|
+
super(options)
|
59
69
|
end
|
60
70
|
|
61
71
|
# rubocop:disable Metrics/AbcSize
|
62
72
|
def publish(message)
|
63
73
|
message.uuid = SecureRandom.uuid if message.uuid.blank?
|
64
74
|
message.correlation_id = SecureRandom.uuid if message.correlation_id.blank?
|
65
|
-
RailwayIpc.logger.info(
|
75
|
+
RailwayIpc.logger.info('Publishing message', log_message_options(message))
|
66
76
|
|
67
77
|
stored_message = message_store.store_message(exchange_name, message)
|
68
78
|
super(RailwayIpc::Rabbitmq::Payload.encode(message))
|
69
79
|
rescue RailwayIpc::InvalidProtobuf => e
|
70
|
-
RailwayIpc.logger.error(
|
80
|
+
RailwayIpc.logger.error('Invalid protobuf', log_message_options(message))
|
71
81
|
raise e
|
72
82
|
rescue ActiveRecord::RecordInvalid => e
|
73
|
-
RailwayIpc.logger.error(
|
83
|
+
RailwayIpc.logger.error('Failed to store outgoing message', log_message_options(message))
|
74
84
|
raise RailwayIpc::FailedToStoreOutgoingMessage.new(e)
|
75
85
|
rescue StandardError => e
|
76
86
|
stored_message&.destroy
|
77
87
|
raise e
|
78
88
|
end
|
79
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
|
80
103
|
end
|
81
104
|
end
|
@@ -11,7 +11,11 @@ module RailwayIpc
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def respond(request)
|
14
|
-
RailwayIpc.logger.info(
|
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(
|
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.
|
82
|
-
|
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(
|
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
|
|
@@ -45,10 +45,12 @@ module RailwayIpc
|
|
45
45
|
raise RailwayIpc::UnhandledMessageError.new("#{self.class} does not know how to handle #{decoded_payload.type}")
|
46
46
|
end
|
47
47
|
rescue StandardError => e
|
48
|
-
RailwayIpc.logger.
|
49
|
-
|
48
|
+
RailwayIpc.logger.error(
|
49
|
+
e.message,
|
50
|
+
feature: 'railway_ipc_consumer',
|
51
|
+
exchange: self.class.exchange_name,
|
52
|
+
queue: self.class.queue_name,
|
50
53
|
error: e.class,
|
51
|
-
error_message: e.message,
|
52
54
|
payload: payload
|
53
55
|
)
|
54
56
|
raise e
|
@@ -57,10 +59,18 @@ module RailwayIpc
|
|
57
59
|
# rubocop:enable Metrics/MethodLength
|
58
60
|
|
59
61
|
# rubocop:disable Metrics/AbcSize
|
62
|
+
# rubocop:disable Metrics/MethodLength
|
60
63
|
def handle_request(payload)
|
61
64
|
response = work(payload)
|
62
65
|
rescue StandardError => e
|
63
|
-
RailwayIpc.logger.error(
|
66
|
+
RailwayIpc.logger.error(
|
67
|
+
'Error responding to message.',
|
68
|
+
exception: e,
|
69
|
+
feature: 'railway_ipc_consumer',
|
70
|
+
exchange: self.class.exchange_name,
|
71
|
+
queue: self.class.queue_name,
|
72
|
+
protobuf: { type: message.class, data: message }
|
73
|
+
)
|
64
74
|
response = self.class.rpc_error_adapter_class.error_message(e, message)
|
65
75
|
ensure
|
66
76
|
if response
|
@@ -70,6 +80,7 @@ module RailwayIpc
|
|
70
80
|
end
|
71
81
|
end
|
72
82
|
# rubocop:enable Metrics/AbcSize
|
83
|
+
# rubocop:enable Metrics/MethodLength
|
73
84
|
|
74
85
|
private
|
75
86
|
|
data/lib/railway_ipc/version.rb
CHANGED
@@ -2,20 +2,20 @@
|
|
2
2
|
|
3
3
|
class AddRailwayIpcConsumedMessages < ActiveRecord::Migration
|
4
4
|
def change
|
5
|
-
create_table :railway_ipc_consumed_messages
|
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,
|
19
|
+
add_index :railway_ipc_consumed_messages, %i[uuid queue], unique: true
|
20
20
|
end
|
21
21
|
end
|
data/railway_ipc.gemspec
CHANGED
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:
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ''
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-27 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.
|
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: '
|
274
|
+
version: '2.5'
|
277
275
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
278
276
|
requirements:
|
279
277
|
- - ">="
|
data/CHANGELOG.MD
DELETED
@@ -1,39 +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.0] - 2020-07-20
|
14
|
-
### Added
|
15
|
-
* CircleCI build that runs the specs
|
16
|
-
* Rubocop (also ran by CircleCI)
|
17
|
-
* New error types for incoming messages
|
18
|
-
* RailwayIpc::Messages::Unknown protobuf
|
19
|
-
|
20
|
-
### Changed
|
21
|
-
* Refactored worker to use ProcessIncomingMessage and IncomingMessage abstractions
|
22
|
-
* Moved decoding logic from ConsumedMessage to IncomingMessage
|
23
|
-
* Removed STATUSES constant from ConsumedMessage
|
24
|
-
* Publisher is no longer a Singleton; kept a Singleton version of the Publisher for backwards compatibility that gives a "deprecated" warning
|
25
|
-
|
26
|
-
### Removed
|
27
|
-
* Removed `BaseMessage` protobuf
|
28
|
-
* NullMessage and NullHandler were removed
|
29
|
-
|
30
|
-
### Fixed
|
31
|
-
* Fixed all Rubocop warnings and errors
|
32
|
-
|
33
|
-
## [0.1.7] - 2020-06-29
|
34
|
-
### Added
|
35
|
-
- 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)
|
36
|
-
|
37
|
-
[Unreleased]: https://github.com/learn-co/railway_ipc_gem/compare/v1.0.0...HEAD
|
38
|
-
[1.0.0]: https://github.com/learn-co/railway_ipc_gem/compare/v0.1.7...v1.0.0
|
39
|
-
[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
|