Class: NATS::Msg

Inherits:
Object
  • Object
show all
Includes:
JetStream::Msg::AckMethods
Defined in:
lib/nats/io/msg.rb,
lib/nats/io/jetstream/msg.rb

Direct Known Subclasses

Service::Request

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.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/nats/io/msg.rb', line 21

def initialize(opts = {})
  @subject = opts[:subject]
  @reply = opts[:reply]
  @data = opts[:data]
  @header = opts[:header]
  @nc = opts[:nc]
  @sub = opts[:sub]

  # JS related
  @ackd = false
  @meta = nil
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



18
19
20
# File 'lib/nats/io/msg.rb', line 18

def data
  @data
end

#headerObject

Returns the value of attribute header.



18
19
20
# File 'lib/nats/io/msg.rb', line 18

def header
  @header
end

#ncObject

Returns the value of attribute nc.



19
20
21
# File 'lib/nats/io/msg.rb', line 19

def nc
  @nc
end

#replyObject

Returns the value of attribute reply.



18
19
20
# File 'lib/nats/io/msg.rb', line 18

def reply
  @reply
end

#subObject

Returns the value of attribute sub.



19
20
21
# File 'lib/nats/io/msg.rb', line 19

def sub
  @sub
end

#subjectObject

Returns the value of attribute subject.



18
19
20
# File 'lib/nats/io/msg.rb', line 18

def subject
  @subject
end

Instance Method Details

#inspectObject



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 header
    dmsg = dup
    dmsg.subject = reply
    dmsg.data = data
    @nc.publish_msg(dmsg)
  else
    @nc.publish(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