Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy people use message/event buses in their code?
    primarykey
    data
    text
    <p>I think that you have heard of message/event buses, it's the single place when all events in the system flow. Similar architectures are found in computer's motherboards and LAN networks. It's a good approach for motherboards and networks as it reduces the number of wires, but is it good for software development? We don't have such restrictions as electronics does.</p> <p>The simplest implementation of message bus/event bus can be like:</p> <pre><code>class EventBus { void addListener(EventBusListener l}{...} void fireEvent(Event e) {...} } </code></pre> <p>Posting events is done with bus.fireEvent(event), receiving messages is enabled by bus.addListener(listener). Such architectures are sometimes used for software development, for example MVP4G implements similar message bus for GWT.</p> <p>Active projects:</p> <ul> <li>Google <a href="https://code.google.com/p/guava-libraries/wiki/EventBusExplained" rel="noreferrer">Guava EventBus</a></li> <li><a href="https://github.com/bennidi/mbassador" rel="noreferrer">MBassador</a> by <a href="https://github.com/bennidi" rel="noreferrer">Benjamin Diedrichsen</a> </li> <li><a href="http://code.mycila.com/" rel="noreferrer">Mycila PubSub</a> by <a href="http://about.me/mathieucarbou" rel="noreferrer">Mathieu Carbou</a></li> <li><a href="http://code.google.com/p/mvp4g/wiki/EventBus" rel="noreferrer">mvp4g Event Bus</a></li> <li><a href="http://code.google.com/p/simpleeventbus/" rel="noreferrer">Simple Java Event Bus</a></li> </ul> <p>Dormant/Dead projects:</p> <ul> <li>Sun/Oracle <a href="http://www.oracle.com/technetwork/java/javase/faq-139166.html" rel="noreferrer">JavaBeans InfoBus</a></li> <li><a href="https://eventbus.dev.java.net/" rel="noreferrer">https://eventbus.dev.java.net/</a> [Broken link]</li> </ul> <p>It's just the popular Observer (Listener) pattern made 'globally' - each object in the system can listen to each message, and I think it's bad, it breaks the Encapsulation principle (each object knows about everything) and Single Responsibility principle (eg when some object needs to a new type of message, event bus often needs to be changed for example to add a new Listener class or a new method in the Listener class).</p> <p>For these reasons I think, that for most software, Observer pattern is better than event bus. What do you think about event bus, does it make any good sense for typical applications?</p> <p>EDIT: I'm not talking about 'big' enterprise solutions like ESB - they can be useful (what's more ESB offers much, much more than just an event bus). I'm asking about usefulness of using message bus in 'regular' Java code for object-to-object connection - some people do it, check the links above. Event bus is probably best solution for telephone-to-telephone communication or computer-to-computer communication because each telefone (or computer) in a network can typically talk to each other, and bus reduces the number of wires. But objects rarely talk to each other - how many collaborators one object can have - 3, 5?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload