Class: Tackle::Consumer::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/tackle/consumer/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, logger, delivery_info, properties, payload) ⇒ Message

Returns a new instance of Message.



9
10
11
12
13
14
15
16
# File 'lib/tackle/consumer/message.rb', line 9

def initialize(connection, logger, delivery_info, properties, payload)
  @connection = connection
  @logger = logger

  @delivery_info = delivery_info
  @properties    = properties
  @payload       = payload
end

Instance Attribute Details

#payloadObject (readonly)

Returns the value of attribute payload.



5
6
7
# File 'lib/tackle/consumer/message.rb', line 5

def payload
  @payload
end

#propertiesObject (readonly)

Returns the value of attribute properties.



6
7
8
# File 'lib/tackle/consumer/message.rb', line 6

def properties
  @properties
end

Instance Method Details

#ackObject



18
19
20
21
22
# File 'lib/tackle/consumer/message.rb', line 18

def ack
  log_info "Sending positive acknowledgement to source queue"
  @connection.channel.ack(delivery_tag)
  log_info "Positive acknowledgement sent"
end

#delivery_tagObject



38
39
40
# File 'lib/tackle/consumer/message.rb', line 38

def delivery_tag
  @delivery_info.delivery_tag
end

#log_error(message) ⇒ Object



46
47
48
# File 'lib/tackle/consumer/message.rb', line 46

def log_error(message)
  @logger.error("[delivery_tag=#{delivery_tag}] #{message}")
end

#log_info(message) ⇒ Object



42
43
44
# File 'lib/tackle/consumer/message.rb', line 42

def log_info(message)
  @logger.info("[delivery_tag=#{delivery_tag}] #{message}")
end

#nackObject



24
25
26
27
28
# File 'lib/tackle/consumer/message.rb', line 24

def nack
  log_error "Sending negative acknowledgement to source queue"
  @connection.channel.nack(delivery_tag)
  log_error "Negative acknowledgement sent"
end

#retry_countObject



30
31
32
33
34
35
36
# File 'lib/tackle/consumer/message.rb', line 30

def retry_count
  if @properties.headers && @properties.headers["retry_count"]
    @properties.headers["retry_count"]
  else
    0
  end
end