Class: Acception::Subscriber::MessageHandler

Inherits:
Object
  • Object
show all
Includes:
Logging, Celluloid
Defined in:
lib/acception/subscriber/message_handler.rb

Constant Summary collapse

BLANK =
'<<blank>>'
ERROR =
'error'
LICENSE_VIOLATION =
'license-violation'
REQUEUE =
true

Instance Method Summary collapse

Instance Method Details

#call(options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/acception/subscriber/message_handler.rb', line 16

def call( options )
  channel       = options[:channel]
  delivery_info = options[:delivery_info]
  payload       = options[:payload]
        = options[:metadata]
  headers       = [:headers]

  debug ANSI.cyan { 'HEADERS' } + " #{headers}"
  debug ANSI.yellow { 'PAYLOAD' } + " #{payload}"

  case resolve_type( payload )
    when ERROR
      handle_error( headers )
    when LICENSE_VIOLATION
      handle_license_violation( headers )
    else
  end

  channel.acknowledge( delivery_info.delivery_tag )
rescue => e
  debug ANSI.red { "ERROR" } + " #{e.message}"
  debug ANSI.red { "ERROR" } + " #{e.backtrace}"
  channel.nack delivery_info.delivery_tag
end