Class: Msgr::Consumer

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

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logging

#log, #log_name

Class Attribute Details

.auto_ack=(value) ⇒ Object (writeonly)

Sets the attribute auto_ack

Parameters:

  • value

    the value to set the attribute auto_ack to.



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

def auto_ack=(value)
  @auto_ack = value
end

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?Boolean

Returns:

  • (Boolean)


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

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

Instance Method Details

#dispatch(message) ⇒ Object



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

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



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

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