The Broker pattern introduces a central coordinator (broker) that mediates communication between various components or modules. It helps in decoupling modules by handling communication and distribution of messages among them.
- Used in distributed systems to coordinate communication between components
- Clients make requests to the broker, which forwards to appropriate servers
Variants
- Direct communication broker system
- Direct link to server
- Message passing broker system
- Focus is on message transmission
- Type of message dictates broker action
- Trader system
- Service identifiers are used to access the right server
- Callback broker system
- Event driven
Usage
- CORBA - Remote method invocation middleware.
- IBM SOM/DSOM - Distributed SOM brokers.
- Microsoft OLE - Allows embedded documents through brokers.
- Web services - SOAP, REST brokers.
Benefits
- Location transparency - Clients unaware of server locations.
- Language transparency - Clients and servers can use different languages.
- Portability - Adding brokers does not require changing clients/servers.
Drawbacks
- Reduced efficiency - Broker indirection adds overhead.
- Reliability - Broker is a single point of failure.
- Testing complexity - Hard to integrate test brokers and servers.
Example
In a distributed system, a message broker (like RabbitMQ or Kafka) serves as an intermediary between different services. It receives messages from one service and routes them to the appropriate destination service.