kookster / activemessaging

ActiveMessaging moved from google code - this will be the latest and greatest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New processor instantiated on every message?

psharpNumerex opened this issue · comments

Am I reading this chunk of _dispatch in gateway.rb correctly?

          execute_filter_chain(:incoming, message, routing) do |m|
            result = subscription.processor_class.new.process!(m)
          end

A new processor object is created for each message? Would it not be better cache the processor object in subscribe_to?

It is following the same pattern as a controller. By making a new one, I can be sure there is no state left over for the instance.

hmm, I can see the point of that, but I might think of it more as a processor implementation issue. Thanks for the quick response!

Is there some need this is not meeting?

I heard some years ago from someone who wanted to be able to keep state in a processor (like a counter), and so didn't want a new instance per call. Are you looking for something similar?

yes, something fairly similar to that. But mostly we'd like to support being a multi-threaded processor.

You want your processor to start multiple threads? Hmm, that should work. I don't think I have done it before though.

On the other hand, I did make a new threaded poller that will have a single poller instance run many threads/processors in one OS process (a la sidekiq).

I haven't doc'd as such, as I am just now putting finishing touches on it, but it's pretty self explanatory.

https://github.com/kookster/activemessaging/blob/master/lib/generators/active_messaging/install/templates/threaded_poller
https://github.com/kookster/activemessaging/blob/master/lib/activemessaging/threaded_poller.rb

Nice work, is it ready for primetime?