Sha256: 3e8416b7cd1cbbf74bdbe3236f66dac10b7b364165b1a2267b073ed12142be39

Contents?: true

Size: 1.54 KB

Versions: 5

Compression:

Stored size: 1.54 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
      "#<NATS::Msg(subject: \"#{@subject}\", reply: \"#{@reply}\", data: #{@data.slice(0, 10).inspect}#{hdr})>"
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
rubypitaya-3.12.5 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/nats-pure-2.2.1/lib/nats/io/msg.rb
rubypitaya-3.12.4 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/nats-pure-2.2.1/lib/nats/io/msg.rb
rubypitaya-3.12.3 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/nats-pure-2.2.1/lib/nats/io/msg.rb
rubypitaya-3.12.2 ./lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/nats-pure-2.2.1/lib/nats/io/msg.rb
nats-pure-2.2.1 lib/nats/io/msg.rb