Class: NATS::Msg

Inherits:
Object show all
Includes:
JetStream::Msg::AckMethods
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/nats-pure-2.2.1/lib/nats/io/msg.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/nats-pure-2.2.1/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

#dataObject

Returns the value of attribute data.



18
19
20
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/nats-pure-2.2.1/lib/nats/io/msg.rb', line 18

def data
  @data
end

#headerObject

Returns the value of attribute header.



18
19
20
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/nats-pure-2.2.1/lib/nats/io/msg.rb', line 18

def header
  @header
end

#replyObject

Returns the value of attribute reply.



18
19
20
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/nats-pure-2.2.1/lib/nats/io/msg.rb', line 18

def reply
  @reply
end

#subjectObject

Returns the value of attribute subject.



18
19
20
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/nats-pure-2.2.1/lib/nats/io/msg.rb', line 18

def subject
  @subject
end

Instance Method Details

#inspectObject



51
52
53
54
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/nats-pure-2.2.1/lib/nats/io/msg.rb', line 51

def inspect
  hdr = ", header=#{@header}" if @header
  "#<NATS::Msg(subject: \"#{@subject}\", reply: \"#{@reply}\", data: #{@data.slice(0, 10).inspect}#{hdr})>"
end

#respond(data = '') ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/nats-pure-2.2.1/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/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/nats-pure-2.2.1/lib/nats/io/msg.rb', line 46

def respond_msg(msg)
  return unless @nc
  @nc.publish_msg(msg)
end