Register an action to be called by dispatching from any channelClient or channelProvider. The return value will be sent back as an acknowledgement to the original caller. You can throw an error to send a negative-acknowledgement and the error will reject the promise returned to the sender by the dispatch call. Once a listener is registered for a particular action, it stays in place receiving and responding to incoming messages until it is removed. This messaging mechanism works exactly the same when messages are dispatched from the provider to a client. However, the provider has an additional publish method that sends messages to all connected clients.
Because multiple clients can share the same name
and uuid
, in order to distinguish between individual clients, the identity
argument in a provider's registered action callback contains an endpointId
property. When dispatching from a provider to a client, the endpointId
property must be provided in order to send an action to a specific client.
Channel Provider
Register an action to be called by clients.
(async ()=> {
const provider = await fin.InterApplicationBus.Channel.create('channelName');
await provider.register('provider-action', (payload, identity) => {
console.log('Action dispatched by client: ', identity);
console.log('Payload sent in dispatch: ', payload);
return { echo: payload };
});
})();
Channel Client
Dispatch an action to a specified provider.
(async ()=> {
const client = await fin.InterApplicationBus.Channel.connect('channelName');
await client.register('client-action', (payload, identity) => {
console.log('Action dispatched by client: ', identity);
console.log('Payload sent in dispatch: ', payload);
return { echo: payload };
});
})();