Broker-based messagingEvery application is connected to the central broker. No application is speaking directly to the other application. All the communication is passed through the broker.
- Firstly, applications don't have to have any idea about location of other applications. The only address they need is the network address of the broker. Broker then routes the messages to the right applications based on business criteria ("queue name", "routing key", "topic", "message properties" etc.) rather than on physical topology (IP addresses, host names).
- Secondly, message sender and message receiver lifetimes don't have to overlap. Sender application can push messages to the broker and terminate. The messages will be available for the receiver application any time later.
- Thirdly, broker model is to some extent resistant to the application failure. So, if the application is buggy and prone to failure, the messages that are already in the broker will be retained even if the application fails.
- Firstly, it requires excessive amount of network communication.
- Secondly, the fact that all the messages have to be passed through the broker can result in broker turning out to be the bottleneck of the whole system. Broker box can be utilised to 100% while other boxes are under-utilised, even idle almost all the time.
Broker as a directory service
Pros:This way we can get high performance and manageability at the same time.
Cons:Does not meet the requirements -> The sender application and the receiver application don't have to have overlapped lifetimes. The messages are stored in the broker while sender is already off and receiver has not yet started. Also, if the application fails, the messages that were already passed to the broker are not lost.
Distributed BrokerThis approach overcomes the issue of broker as the bottleneck or single point of failure by letting us use multiple message queues (each registered with the central directory service as a separate application/OSGi bundle).
- Overcomes the limitation of message broker being single point of failure.
- Retains all advantages of the broker based messaging that applications don't need to know each other's address and they can lookup the message queues in the directory service and send/receive messages on the message queue.