Class: Msgr::Consumer

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/msgr/consumer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#log, #log_name

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



7
8
9
# File 'lib/msgr/consumer.rb', line 7

def message
  @message
end

Class Method Details

.auto_ack=(val) ⇒ Object



17
18
19
# File 'lib/msgr/consumer.rb', line 17

def auto_ack=(val)
  @auto_ack = val
end

.auto_ack?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/msgr/consumer.rb', line 13

def auto_ack?
  @auto_ack || @auto_ack.nil?
end

Instance Method Details

#dispatch(message) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/msgr/consumer.rb', line 22

def dispatch(message)
  @message = message

  action = message.route.action.to_sym

  unless respond_to?(action)
    raise Msgr::NoAction.new \
      "No action `#{action}` for `#{self.class.name}`."
  end

  log(:debug) { "Invoke action #{action.inspect}." }

  send action

  log(:debug) { "Action #{action.inspect} done." }
end

#publish(data, opts = {}) ⇒ Object



39
40
41
# File 'lib/msgr/consumer.rb', line 39

def publish(data, opts = {})
  Msgr.client.publish(data, opts)
end