Class: ActiveMessaging::Adapters::Amqp::AmqpMessage

Inherits:
Emissary::Message
  • Object
show all
Defined in:
lib/activemessaging/adapters/amqp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, queue_name = nil) ⇒ AmqpMessage

Returns a new instance of AmqpMessage.



179
180
181
182
183
184
185
186
187
188
# File 'lib/activemessaging/adapters/amqp.rb', line 179

def initialize(data, queue_name = nil)
  data[:data] = data.delete(:body) unless (data[:data] && !data[:body])

  super(data)
  
  @delivery_tag ||= (data[:headers][:delivery_tag] rescue nil)
  @destination  ||= (data[:headers][:destination] rescue nil) || queue_name || routing_key
  
  @command = "MESSAGE"
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



176
177
178
# File 'lib/activemessaging/adapters/amqp.rb', line 176

def command
  @command
end

#delivery_tagObject

Returns the value of attribute delivery_tag.



177
178
179
# File 'lib/activemessaging/adapters/amqp.rb', line 177

def delivery_tag
  @delivery_tag
end

#destinationObject

Returns the value of attribute destination.



177
178
179
# File 'lib/activemessaging/adapters/amqp.rb', line 177

def destination
  @destination
end

Instance Method Details

#headersObject



192
193
194
195
196
197
# File 'lib/activemessaging/adapters/amqp.rb', line 192

def headers
  super.merge({
    :destination  => routing_key,
    :delivery_tag => @delivery_tag
  })
end

#matches_subscription?(subscription) ⇒ Boolean

Returns:

  • (Boolean)


199
200
201
202
203
204
205
206
207
208
209
# File 'lib/activemessaging/adapters/amqp.rb', line 199

def matches_subscription?(subscription)
  # use routing key first, otherwise, use the defined destination value
  destination = subscription.subscribe_headers[:routing_key] || subscription.destination.value.to_s
  
  if destination.match(/(\#|\*)/)
    dest_regex = ::Regexp.new(destination.gsub('.*', '[.][^.]+').gsub(/\.\#.*/, '[.].*'))
    !!(headers[:destination].to_s =~ dest_regex)
  else
    !!(headers[:destination].to_s == destination)
  end
end