tirsen / activemessaging

ActiveMessaging is an attempt to bring the simplicity and elegance of Rails development to the world of messaging. Messaging, (or event-driven architecture) is widely used for enterprise integration, with frameworks such as Java's JMS, and products such as ActiveMQ, Tibco, IBM MQSeries etc
0 stars 0 forks source link

Request change to ActiveMessaging::AbortMessageException #37

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Raising ActiveMessaging::AbortMessageException is a great way to indicate
that a message needs to be re-queued, however there are some conditions in
which after the message is re-queued, we want to exit the entire poller
process (for example, if a message processing method detecs that the
database server has a problem and can't reconnect).  If the poller were
stopped and restarted (in some of these instances), the error condition is
remedied.  

I'd like to suggest that ActiveMessaging::AbortMessageException be extended
to optionally take an options hash on the constructor, so that parameters
can be passed with the exception. I would also propose that the first
parameter to be handled is the must_exit parameter, which indicates to the
higher-level processor to exit the processor after the message has been
requeued. 

in activemessaging.rb, the exception class becomes:
class AbortMessageException < Exception #:nodoc:
    attr_reader :exit_process
    def initialize(options={})
      @exit_process = options[:exit_process]
    end
  end

In gateway.rb, the handling clause for the exception becomes:
              rescue ActiveMessaging::AbortMessageException =>exception_detail
                abort_message subscription, message
                abort = true
                Process.exit if exception_detail.exit_process
                return
              ensure
                acknowledge_message subscription, message unless abort
              end
And the processor code that detects the situation that requires a complete
restart signals that by: 
raise ActiveMessaging::AbortMessageException.new({:exit_process=>true})

(monit or some other type of method could be used to see that poller has
exited, and have it restart)

Original issue reported on code.google.com by brian.mo...@gmail.com on 8 Sep 2008 at 4:42

GoogleCodeExporter commented 9 years ago
Oops, please change must_exit to exit_process in the above message.

Original comment by brian.mo...@gmail.com on 8 Sep 2008 at 4:43

GoogleCodeExporter commented 9 years ago
It looks like an unsubscribe will have to occur before the Process.exit, 
otherwise
the recently requeued message will be lost on exit, since it's been read 
already.

Original comment by brian.mo...@gmail.com on 8 Sep 2008 at 5:38