Class: NATS::Msg
- Inherits:
-
Object
- Object
- NATS::Msg
- Includes:
- JetStream::Msg::AckMethods
- Defined in:
- lib/nats/io/msg.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#header ⇒ Object
Returns the value of attribute header.
-
#reply ⇒ Object
Returns the value of attribute reply.
-
#subject ⇒ Object
Returns the value of attribute subject.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Msg
constructor
A new instance of Msg.
- #inspect ⇒ Object
- #respond(data = '') ⇒ Object
- #respond_msg(msg) ⇒ Object
Methods included from JetStream::Msg::AckMethods
#ack, #ack_sync, #in_progress, #metadata, #nak, #term
Constructor Details
#initialize(opts = {}) ⇒ Msg
Returns a new instance of Msg.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/nats/io/msg.rb', line 23 def initialize(opts={}) @subject = opts[:subject] @reply = opts[:reply] @data = opts[:data] @header = opts[:header] @nc = opts[:nc] @sub = opts[:sub] @ackd = false @meta = nil end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
18 19 20 |
# File 'lib/nats/io/msg.rb', line 18 def data @data end |
#header ⇒ Object
Returns the value of attribute header.
18 19 20 |
# File 'lib/nats/io/msg.rb', line 18 def header @header end |
#reply ⇒ Object
Returns the value of attribute reply.
18 19 20 |
# File 'lib/nats/io/msg.rb', line 18 def reply @reply end |
#subject ⇒ Object
Returns the value of attribute subject.
18 19 20 |
# File 'lib/nats/io/msg.rb', line 18 def subject @subject end |
Instance Method Details
#inspect ⇒ Object
51 52 53 54 55 56 |
# File 'lib/nats/io/msg.rb', line 51 def inspect hdr = ", header=#{@header}" if @header dot = '...' if @data.length > 10 dat = "#{data.slice(0, 10)}#{dot}" "#<NATS::Msg(subject: \"#{@subject}\", reply: \"#{@reply}\", data: #{dat.inspect}#{hdr})>" end |
#respond(data = '') ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/nats/io/msg.rb', line 34 def respond(data='') return unless @nc if self.header dmsg = self.dup dmsg.subject = self.reply dmsg.data = data @nc.publish_msg(dmsg) else @nc.publish(self.reply, data) end end |
#respond_msg(msg) ⇒ Object
46 47 48 49 |
# File 'lib/nats/io/msg.rb', line 46 def respond_msg(msg) return unless @nc @nc.publish_msg(msg) end |