# @(#) MQMBID sn=pkoa-L150203 su=BCAC7F69-80BD-4CA4-AF88-E07D09E380A0 pn=appmsging/ruby/mqlight/lib/mqlight/delivery.rb # # # Licensed Materials - Property of IBM # # 5725-P60 # # (C) Copyright IBM Corp. 2014, 2015 # # US Government Users Restricted Rights - Use, duplication or # disclosure restricted by GSA ADP Schedule Contract with # IBM Corp. # require 'uri' module Mqlight # This class represents an attempt to deliver message data to the client. class Delivery # @return [String] the message data associated with this delivery attr_reader :data # @return [String] the topic that the message, delivered by this # deliver, was originally sent to. attr_reader :topic # @return [String] the topic pattern that the client subscribed to in order # to receive this message delivery attr_reader :topic_pattern # @return [Integer] the remaining time to live period for this message in # milliseconds. attr_reader :ttl # @return [String] the share name specified when the client subscribed to # the destination from which the message was received. This # property will not be nil if the client subscribed to a # private destination. attr_reader :share # Called to confirm that the code that has received this message has # processed the message to its satisfaction. When the server receives this # confirmation it will make no further attempt to deliver this message to # the client and discard its copy of the message. attr_reader :confirm # def initialize(message, destination, client, tracker) fail ArgumentError, 'message must be a Qpid::Proton::Message.' unless message.is_a? Qpid::Proton::Message fail ArgumentError, 'destination must be an Mqlight::Destination.' unless destination.is_a? Mqlight::Destination @data = message.body @topic = URI.decode(URI(URI.encode(message.address)).path.partition('/').last) @topic_pattern = destination.topic_pattern @ttl = message.ttl @share = destination.share @tracker = tracker @connect_id = client.connect_id # Define the manual/deferred confirm method for this message. if (!destination.auto_confirm) @confirm = Proc.new { fail Mqlight::StoppedError, 'Not started.' unless client.started? fail Mqlight::NetworkError, 'client has reconnected since this message was received' \ if @connect_id != client.connect_id client.settle(@tracker) } end end # def to_s info = "{" info << "data: " + @data.to_s.force_encoding("UTF-8") unless @data.nil? info << ", topic: " + @topic.to_s.force_encoding("UTF-8") \ unless @topic.nil? info << ", topic_pattern: " + @topic_pattern.to_s.force_encoding("UTF-8") unless @topic_pattern.nil? info << ", ttl: " + @ttl.to_s unless @ttl.nil? info << ", share: " + @share.to_s.force_encoding("UTF-8") \ unless @share.nil? info << ", confirm: " + @confirm.to_s unless @confirm.nil? info << ", tracker: " + @tracker.to_s unless @tracker.nil? info << "}" end end end