Module: Messaging::Write
- Included in:
- Controls::Write::Example, Substitute::Write
- Defined in:
- lib/messaging/write.rb,
lib/messaging/write/substitute.rb
Defined Under Namespace
Modules: Build, Call, Configure, Substitute, Telemetry Classes: Error
Class Method Summary collapse
Instance Method Summary collapse
- #call(message_or_batch, stream_name, expected_version: nil, reply_stream_name: nil) ⇒ Object (also: #write)
- #initial(message, stream_name) ⇒ Object (also: #write_initial)
- #message_data_batch(message_batch, reply_stream_name = nil) ⇒ Object
- #reply(message) ⇒ Object
Class Method Details
.included(cls) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/messaging/write.rb', line 5 def self.included(cls) cls.class_exec do include Dependency include TemplateMethod include Log::Dependency dependency :message_writer dependency :telemetry, ::Telemetry extend Build extend Call extend Configure template_method! :configure const_set :Substitute, Substitute end end |
Instance Method Details
#call(message_or_batch, stream_name, expected_version: nil, reply_stream_name: nil) ⇒ Object Also known as: write
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/messaging/write.rb', line 48 def call(, stream_name, expected_version: nil, reply_stream_name: nil) unless .is_a? Array logger.trace(tag: :write) { "Writing message (Type: #{.class.}, Stream Name: #{stream_name}, Expected Version: #{expected_version.inspect}, Reply Stream Name: #{reply_stream_name.inspect})" } else logger.trace(tag: :write) do = .map {|| .class. }.uniq.join(', ') "Writing batch (Types: #{}, Stream Name: #{stream_name}, Expected Version: #{expected_version.inspect}, Reply Stream Name: #{reply_stream_name.inspect})" end end logger.trace(tags: [:data, :message]) { .pretty_inspect } = Array() = (, reply_stream_name) ## Can be called `position` - Scott, Tue Mar 26 2024 last_position = .(, stream_name, expected_version: expected_version) unless .is_a? Array logger.info(tag: :write) { "Wrote message (Type: #{.class.}, Stream Name: #{stream_name}, Position: #{last_position}, Expected Version: #{expected_version.inspect}, Reply Stream Name: #{reply_stream_name.inspect})" } else logger.info(tag: :write) do = .map {|| .class. }.uniq.join(', ') "Wrote batch (Types: #{}, Stream Name: #{stream_name}, Position: #{last_position}, Expected Version: #{expected_version.inspect}, Reply Stream Name: #{reply_stream_name.inspect})" end end logger.info(tags: [:data, :message]) { .pretty_inspect } .each do || telemetry.record :written, Telemetry::Data.new(, stream_name, expected_version, reply_stream_name) end last_position end |
#initial(message, stream_name) ⇒ Object Also known as: write_initial
123 124 125 |
# File 'lib/messaging/write.rb', line 123 def initial(, stream_name) write(, stream_name, expected_version: :no_stream) end |
#message_data_batch(message_batch, reply_stream_name = nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/messaging/write.rb', line 83 def (, reply_stream_name=nil) = [] .each do || unless reply_stream_name.nil? ..reply_stream_name = reply_stream_name end << Message::Export.() end end |
#reply(message) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/messaging/write.rb', line 96 def reply() if .is_a? Array error_msg = "Cannot reply with a batch" logger.error { error_msg } raise Error, error_msg end = . reply_stream_name = .reply_stream_name logger.trace(tags: [:write, :reply]) { "Replying (Message Type: #{.}, Stream Name: #{reply_stream_name.inspect})" } if reply_stream_name.nil? error_msg = "Message has no reply stream name. Cannot reply. (Message Type: #{.})" logger.error { error_msg } logger.error(tags: [:data, :message]) { .pretty_inspect } raise Error, error_msg end .clear_reply_stream_name write(, reply_stream_name).tap do logger.info(tags: [:write, :reply]) { "Replied (Message Type: #{.}, Stream Name: #{reply_stream_name})" } telemetry.record :replied, Telemetry::Data.new(, reply_stream_name) end end |