Module: RSMP::Proxy::Modules::Send
- Included in:
- RSMP::Proxy
- Defined in:
- lib/rsmp/proxy/modules/send.rb
Overview
Message sending functionality Handles sending messages, validation, and buffering
Instance Method Summary collapse
- #apply_nts_message_attributes(message) ⇒ Object
- #buffer_message(message, error = nil) ⇒ Object
- #handle_send_schema_error(message, error) ⇒ Object
- #log_send(message, reason = nil) ⇒ Object
- #send_message(message, reason = nil, validate: true, force: false, buffer: true) ⇒ Object
- #send_message_and_collect(message, collector, validate: true) ⇒ Object
Instance Method Details
#apply_nts_message_attributes(message) ⇒ Object
69 70 71 72 |
# File 'lib/rsmp/proxy/modules/send.rb', line 69 def () .attributes['ntsOId'] = main && main.ntsoid ? main.ntsoid : '' .attributes['xNId'] = main && main.xnid ? main.xnid : '' end |
#buffer_message(message, error = nil) ⇒ Object
38 39 40 41 42 |
# File 'lib/rsmp/proxy/modules/send.rb', line 38 def (, error = nil) str = "Cannot send #{.type} because the connection is closed." log str, message: , level: :error raise error if error end |
#handle_send_schema_error(message, error) ⇒ Object
7 8 9 10 11 12 |
# File 'lib/rsmp/proxy/modules/send.rb', line 7 def handle_send_schema_error(, error) schemas_string = error.schemas.map { |schema| "#{schema.first}: #{schema.last}" }.join(', ') str = "Could not send #{.type} because schema validation failed (#{schemas_string}): #{error.}" log str, message: , level: :error distribute_error error.exception("#{str} #{.json}") end |
#log_send(message, reason = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rsmp/proxy/modules/send.rb', line 44 def log_send(, reason = nil) str = if reason "Sent #{.type} #{reason}" else "Sent #{.type}" end if .type == 'MessageNotAck' log str, message: , level: :warning else log str, message: , level: :log end end |
#send_message(message, reason = nil, validate: true, force: false, buffer: true) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/rsmp/proxy/modules/send.rb', line 14 def (, reason = nil, validate: true, force: false, buffer: true) unless force || connected? error = NotReady.new raise error unless buffer return (, error) end raise IOError unless @protocol .direction = :out .generate_json .validate schemas unless validate == false @protocol.write_lines .json expect_acknowledgement distribute log_send , reason rescue NotReady, IOError => e raise e unless buffer , e rescue SchemaError, RSMP::Schema::Error => e handle_send_schema_error(, e) end |
#send_message_and_collect(message, collector, validate: true) ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/rsmp/proxy/modules/send.rb', line 58 def (, collector, validate: true) task = @task.async do |t| t.annotate 'send_message_and_collect' collector.collect collector end , validate: validate collector = task.wait { sent: , collector: collector } end |