Log events that get published to the dead-letter queue
Set up the output device. By default it's STDERR, but it can be anything that responds to <<.
# File lib/symphony/tasks/failure_logger.rb, line 27
def initialize( * )
super
@output = $stderr
$stderr.sync = true
end
Return a logging message part based on the specified deaths
.
deaths - An Array of Hashes derived from the 'x-death' headers of the message
# File lib/symphony/tasks/failure_logger.rb, line 95
def log_deaths( deaths )
message = ''
deaths.each do |death|
message << " %s-{%s}->%s (%s)" % [
death['exchange'],
death['routing-keys'].join(','),
death['queue'],
death['reason'],
]
end
return message
end
Log one or more deaths
of the failed event.
# File lib/symphony/tasks/failure_logger.rb, line 59
def log_failure( payload, metadata )
raise "No headers; not a dead-lettered message?" unless
metadata[:properties] &&
metadata[:properties][:headers]
deaths = metadata[:properties][:headers]['x-death'] or
raise "No x-death header; not a dead-lettered message?"
message = self.log_prefix( payload, metadata )
message << self.log_deaths( deaths )
message << self.log_payload( payload, metadata )
@output << message << "\n"
end
Return a logging message part based on the specified message payload
.
# File lib/symphony/tasks/failure_logger.rb, line 82
def log_payload( payload, metadata )
return " -- %0.2fKB %s payload: %p" % [
ObjectSpace.memsize_of(payload) / 1024.0,
metadata[:content_type],
payload,
]
end
Return a logging message prefix based on the specified routing_key
and deaths
.
# File lib/symphony/tasks/failure_logger.rb, line 76
def log_prefix( payload, metadata )
return "[%s]: " % [ Time.now.strftime('%Y-%m-%d %H:%M:%S.%4N') ]
end
Log the failure :headers=>{
"x-death"=>[{ "reason"=>"rejected", "queue"=>"auditor", "time"=>2014-03-12 18:55:10 -0700, "exchange"=>"events", "routing-keys"=>["some.stuff"] }]
}
# File lib/symphony/tasks/failure_logger.rb, line 52
def work( payload, metadata )
self.log_failure( payload, metadata )
return true
end