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) ⇒ Object
- #handle_send_schema_error(message, error) ⇒ Object
- #log_send(message, reason = nil) ⇒ Object
- #send_message(message, reason = nil, validate: true, force: false) ⇒ Object
- #send_message_and_collect(message, collector, validate: true) ⇒ Object
Instance Method Details
#apply_nts_message_attributes(message) ⇒ Object
61 62 63 64 |
# File 'lib/rsmp/proxy/modules/send.rb', line 61 def () .attributes['ntsOId'] = main && main.ntsoid ? main.ntsoid : '' .attributes['xNId'] = main && main.xnid ? main.xnid : '' end |
#buffer_message(message) ⇒ Object
31 32 33 34 |
# File 'lib/rsmp/proxy/modules/send.rb', line 31 def () # TODO # log "Cannot send #{message.type} because the connection is closed.", message: message, level: :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
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rsmp/proxy/modules/send.rb', line 36 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) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rsmp/proxy/modules/send.rb', line 14 def (, reason = nil, validate: true, force: false) raise NotReady if !force && !connected? raise IOError unless @protocol .direction = :out .generate_json .validate schemas unless validate == false @protocol.write_lines .json expect_acknowledgement distribute log_send , reason rescue IOError rescue SchemaError, RSMP::Schema::Error => e handle_send_schema_error(, e) end |
#send_message_and_collect(message, collector, validate: true) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rsmp/proxy/modules/send.rb', line 50 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 |