-
Notifications
You must be signed in to change notification settings - Fork 5
Description
To improve interoperability of the message broker with other messaging systems, we should add an interface for plugging in adapters which map messagebroker messages into messages of other systems in a way which is transparent to the publisher/subscriber of those messages.
The proposal is to introduce a new IMessageBrokerAdapter interface which can be given a configuration object to specify what channels should be exposed or consumed via the adapter. This adapter is then registered with an instance of the messagebroker and used behind the scenes for all relevant messages that are sent through that instance of the broker.
export interface IMessageBrokerAdapter<T> {
readonly id: string;
connect(): Promise<void>;
disconnect(): Promise<void>;
sendMessage(channelName: keyof T, message: IMessage): Promise<void>;
subscribeToMessages(channelName: keyof T): Observable<IMessage>;
isConnected(): boolean;
}
Here's a diagram to illustrate the separation of the application from the external messaging system.
graph TD
App[Application] --> MB[MessageBroker]
MB --> Channel[Internal Channels]
MB --> Registry[Adapter Registry]
Registry --> Adapter[IMessageBrokerAdapter]
Adapter --> |sendMessage| External[External System]
External --> |subscribeToMessages| Adapter
Adapter --> |publishes to| Channel
Channel --> |sends via| Adapter
classDef interface fill:#e3f2fd,color:#000
classDef core fill:#f3e5f5,color:#000
classDef external fill:#fff3e0,color:#000
class Adapter interface
class App,MB,Channel,Registry core
class External external
FDC3 Example:
const broker = messagebroker<IChannels>();
const fdc3Adapter: IMessageBrokerAdapter<IChannels> = new FDC3Adapter<IChannels>();
await fdc3Adapter.connect();
broker.registerAdapter(fdc3Adapter);
With the initial config done, the app can interact with the message broker with no knowledge of how the fdc3 communication is done.
broker.get('instrument').subscribe((message) => {
console.log('Received instrument update:', message.data);
});
// publishes intent
broker.create('chart-request').publish({
type: 'fdc3.instrument',
name: 'Microsoft Corp',
id: {
ticker: 'MSFT'
},
timeframe: '1D'
});
// internal only
broker.create('price-updates').publish({
ticker: 'AAPL',
price: 151.20,
timestamp: Date.now(),
volume: 100000
});