Class Beetle::Handler
In: lib/beetle/handler.rb
Parent: Object

Instances of class Handler are created by the message processing logic in class Message. There should be no need to ever create them in client code, except for testing purposes.

Most applications will define Handler subclasses and override the process, error and failure methods.

Methods

call   error   failure   initialize   logger   process  

Included Modules

Logging

Attributes

message  [R]  the Message instance which caused the handler to be created

Public Class methods

returns the configured Beetle logger

[Source]

    # File lib/beetle/handler.rb, line 87
87:     def self.logger
88:       Beetle.config.logger
89:     end

Public Instance methods

called when a message should be processed. if the message was caused by an RPC, the return value will be sent back to the caller. calls the initialized processor proc if a processor proc was specified when creating the Handler instance. calls method process if no proc was given. make sure to call super if you override this method in a subclass.

[Source]

    # File lib/beetle/handler.rb, line 36
36:     def call(message)
37:       @message = message
38:       if @processor
39:         @processor.call(message)
40:       else
41:         process
42:       end
43:     end

called when handler execution raised an exception and no error callback was specified when the handler instance was created

[Source]

    # File lib/beetle/handler.rb, line 75
75:     def error(exception)
76:       logger.error "Beetle: handler execution raised an exception: #{exception}"
77:     end

called when message processing has finally failed (i.e., the number of allowed handler execution attempts or the number of allowed exceptions has been reached) and no failure callback was specified when this handler instance was created.

[Source]

    # File lib/beetle/handler.rb, line 82
82:     def failure(result)
83:       logger.error "Beetle: handler has finally failed"
84:     end

called for message processing if no processor was specfied when the handler instance was created

[Source]

    # File lib/beetle/handler.rb, line 47
47:     def process
48:       logger.info "Beetle: received message #{message.inspect}"
49:     end

Protected Instance methods

optionally capture processor, error and failure callbacks

[Source]

    # File lib/beetle/handler.rb, line 25
25:     def initialize(processor=nil, opts={}) #:notnew:
26:       @processor = processor
27:       @error_callback = opts[:errback]
28:       @failure_callback = opts[:failback]
29:     end

[Validate]