title: What kind of "EventBus" to use in Spring? Built-in, Reactor, Akka?
body: <p>We're going to start a new Spring 4 application in a few weeks. And we'd like to use some event-driven architecture. This year I read here and there about "Reactor" and while looking for it on the web, I stumbled upon "Akka".</p>
  
  <p>So for now we have 3 choices:</p>
  
  <ul>
  <li>Spring's <code>ApplicationEvent</code>: <a href="http://docs.spring.io/spring/docs/4.0.0.RELEASE/javadoc-api/org/springframework/context/ApplicationEvent.html" rel="noreferrer">http://docs.spring.io/spring/docs/4.0.0.RELEASE/javadoc-api/org/springframework/context/ApplicationEvent.html</a></li>
  <li><code>Reactor</code>: <a href="https://github.com/reactor/reactor#reactor" rel="noreferrer">https://github.com/reactor/reactor#reactor</a></li>
  <li><code>Akka</code>: <a href="http://akka.io/" rel="noreferrer">http://akka.io/</a></li>
  </ul>
  
  <p>I couldn't find a real comparison of those.</p>
  
  <hr>
  
  <p>For now we just need something like:</p>
  
  <ul>
  <li><code>X</code> registers to listen for <code>Event E</code></li>
  <li><code>Y</code> registers to listen for <code>Event E</code></li>
  <li><code>Z</code> sends an <code>Event E</code></li>
  </ul>
  
  <p>And then <code>X</code> and <code>Y</code> will receive and handle the event.</p>
  
  <p>We will most likely use this in a async way, but for sure there will be also some synchronous scenarios. And we most likely send always a class as event. (The Reactor samples mostly make use of Strings and String patterns, but it also supports Objects).</p>
  
  <hr>
  
  <p>As far as I understood, <code>ApplicationEvent</code> works synchronous by default and <code>Reactor</code> works the async way. And <code>Reactor</code> also allows to use the <code>await()</code> method to make it kinda synchronous. <code>Akka</code> provides more or less the same as <code>Reactor</code>, but also supports Remoting.</p>
  
  <p>Concerning Reactor's <code>await()</code> method: Can it wait for multiple threads to complete? Or maybe even a partial set of those threads? If we take the example from above:</p>
  
  <ul>
  <li><code>X</code> registers to listen for <code>Event E</code></li>
  <li><code>Y</code> registers to listen for <code>Event E</code></li>
  <li><code>Z</code> sends an <code>Event E</code></li>
  </ul>
  
  <p>Is it possible to make it synchronous, by saying: Wait for <code>X</code> <strong>and</strong> <code>Y</code> to complete. And is it possible to make it wait just for <code>X</code>, but not for <code>Y</code>?</p>
  
  <hr>
  
  <p>Maybe there are also some alternatives? What about for example JMS?</p>
  
  <p>Lot of questions, but hopefully you can provide some answers!</p>
  
  <p>Thank you!</p>
  
  <hr>
  
  <h2>EDIT: Example use cases</h2>
  
  <ol>
  <li><p>When a specific event gets fired, I'd like to create 10000 emails. Every email has to get generated with user specific content. So I'd create a lot of threads (max = system cpu cores) which create the mails and do not block the caller thread, 'cause this can take some minutes.</p></li>
  <li><p>When a specific event gets fired, I'd like to collect information from an unknown number of services. Each fetch takes about 100ms. Here I could imagine using Reactor's <code>await</code>, 'cause I need those information for continuing my work in the main thread.</p></li>
  <li><p>When a specific event gets fired, I'd like to perform some operations based on application configuration. So the application must be able to dynamically (un)register comsumers/event handlers. They'll do their own stuff with the Event and I don't care. So I would create a thread for every of those handlers and just continue doing my work in the main thread.</p></li>
  <li><p>Simple decoupling: I basically know all receivers, but I just don't want to call every receiver in my code. This should mostly get done synchronously.</p></li>
  </ol>
  
  <p>Sound like I need a ThreadPool or a RingBuffer. Do those frameworks have dynamic RingBuffers, which grow in size if needed?</p>