Sha256: 0414db4b9a98927a9af9bee435f1d8ef4eebc0a776377af424e78e4c212abd22
Contents?: true
Size: 1.61 KB
Versions: 2
Compression:
Stored size: 1.61 KB
Contents
# Copyright 2016-2021 The NATS Authors # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # require_relative 'jetstream' module NATS class Msg attr_accessor :subject, :reply, :data, :header # Enhance it with ack related methods from JetStream to ack msgs. include JetStream::Msg::AckMethods 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 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 def respond_msg(msg) return unless @nc @nc.publish_msg(msg) end 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 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
nats-pure-2.4.0 | lib/nats/io/msg.rb |
nats-pure-2.3.0 | lib/nats/io/msg.rb |