Class: ActiveMessaging::Processor

Inherits:
Object
  • Object
show all
Includes:
MessageSender
Defined in:
lib/activemessaging/processor.rb,
lib/activemessaging/adapters/amqp.rb

Direct Known Subclasses

ApplicationProcessor

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from MessageSender

included, #publish, #publish_with_reset, #receive

Instance Attribute Details

#messageObject (readonly)

Returns the value of attribute message.



7
8
9
# File 'lib/activemessaging/processor.rb', line 7

def message
  @message
end

Class Method Details

.subscribes_to(destination_name, headers = {}) ⇒ Object



10
11
12
# File 'lib/activemessaging/processor.rb', line 10

def subscribes_to destination_name, headers={}
  ActiveMessaging::Gateway.subscribe_to destination_name, self, headers
end

Instance Method Details

#loggerObject



15
16
17
# File 'lib/activemessaging/processor.rb', line 15

def logger()
  @@logger ||= ActiveMessaging.logger
end

#on_error(exception) ⇒ Object



23
24
25
# File 'lib/activemessaging/processor.rb', line 23

def on_error(exception)
  raise exception
end

#on_message(message) ⇒ Object

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/activemessaging/processor.rb', line 19

def on_message(message)
  raise NotImplementedError.new("Implement the on_message method in your own processor class that extends ActiveMessaging::Processor")
end

#process!(message) ⇒ Object

Bind the processor to the current message so that the processor could potentially access headers and other attributes of the message



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/activemessaging/processor.rb', line 29

def process!(message)
  @message = message
  return on_message(message.body)
rescue Object=>err
  begin
    on_error(err)
  rescue ActiveMessaging::AbortMessageException => rpe
    logger.error "Processor:process! - AbortMessageException caught."
    raise rpe
  rescue Object=>ex
    logger.error "Processor:process! - error in on_error, will propagate no further: #{ex.message}\n\t#{ex.backtrace.join("\n\t")}"
  end
end