Class: Mqlight::Delivery

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/mqlight/delivery.rb

Overview

This class represents an attempt to deliver message data to the client.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger, logger

Constructor Details

#initialize(message, destination, thread_vars) ⇒ Delivery

Returns a new instance of Delivery.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/mqlight/delivery.rb', line 59

def initialize(message, destination, thread_vars)
  logger.entry(@id) { self.class.to_s + '#' + __method__.to_s }
  parms = Hash[
    'message', Mqlight::Util.truncate(message.to_s),
    'destination', destination.to_s,
    'thread_vars', thread_vars]
  logger.parms(@id, parms) { self.class.to_s + '#' + __method__.to_s }

  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

  @thread_vars = thread_vars
  @data = message.body
  @topic = message.address
  if @topic.start_with?('amqp://')
    @topic = @topic.partition(%r{amqp://[^/]*/}).last
  end
  @topic_pattern = destination.topic_pattern
  @ttl = message.ttl
  @share = destination.share
  @tracker = @thread_vars.proton.tracker
  @connect_id = @thread_vars.connect_id
  @malformed = Malformed.new(message.instructions).as_hash if message.instructions 
  # Define the manual/deferred confirm method for this message.
  unless destination.auto_confirm
    @confirm = proc do
      fail Mqlight::StoppedError, 'Not started.' unless started?
      fail Mqlight::NetworkError,
           'client has reconnected since this message was received' \
        if @connect_id != @thread_vars.connect_id

      @thread_vars.proton.settle(@tracker)
    end
  end
  logger.exit(@id) { self.class.to_s + '#' + __method__.to_s }
rescue => e
  logger.throw(nil, e) { self.class.to_s + '#' + __method__.to_s }
  raise e
end

Instance Attribute Details

#confirmObject (readonly)

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.



51
52
53
# File 'lib/mqlight/delivery.rb', line 51

def confirm
  @confirm
end

#dataString (readonly)

Returns the message data associated with this delivery.

Returns:

  • (String)

    the message data associated with this delivery



27
28
29
# File 'lib/mqlight/delivery.rb', line 27

def data
  @data
end

#malformedMalformed (readonly)

declared as malformed. The structure contains the information associated with the malformed message.

Returns:

  • (Malformed)

    only present when the received message has been



56
57
58
# File 'lib/mqlight/delivery.rb', line 56

def malformed
  @malformed
end

#shareString (readonly)

Returns 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.

Returns:

  • (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.



45
46
47
# File 'lib/mqlight/delivery.rb', line 45

def share
  @share
end

#topicString (readonly)

Returns the topic that the message, delivered by this deliver, was originally sent to.

Returns:

  • (String)

    the topic that the message, delivered by this deliver, was originally sent to.



31
32
33
# File 'lib/mqlight/delivery.rb', line 31

def topic
  @topic
end

#topic_patternString (readonly)

Returns the topic pattern that the client subscribed to in order to receive this message delivery.

Returns:

  • (String)

    the topic pattern that the client subscribed to in order to receive this message delivery



35
36
37
# File 'lib/mqlight/delivery.rb', line 35

def topic_pattern
  @topic_pattern
end

#ttlInteger (readonly)

Returns the remaining time to live period for this message in milliseconds.

Returns:

  • (Integer)

    the remaining time to live period for this message in milliseconds.



39
40
41
# File 'lib/mqlight/delivery.rb', line 39

def ttl
  @ttl
end

Instance Method Details

#started?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/mqlight/delivery.rb', line 103

def started?
  @thread_vars.state == :started
end

#to_sObject

Returns summary of contains.

Returns:

  • summary of contains



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/mqlight/delivery.rb', line 108

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 << ', malformed: ' + @malformed.to_s unless @malformed.nil?
  info << '}'
end