SDK comes with wrappers around different node modules for sending event through different channels in a single interface named Channel
.
The SDK currently supports the following channels:
import { Events } from "@ssofy/node-sdk";
...
const eventChannel = new Events.NodeEventChannel({
// EventEmitter options
});
eventChannel.subscribe('my-event', (event: string, message?: any) => {
console.log(`{[Event] ${event}:`, message);
});
eventChannel.publish('my-event', {
message: 'test',
});
Installing dependencies:
npm i redis -S
import { Events } from "@ssofy/node-sdk";
import { createClient } from 'redis';
...
const client = createClient();
client.connect();
const eventChannel = new Events.RedisEventChannel(
client, // publisher client
client, // subscriber client
'sso:', // prefix
);
eventChannel.subscribe('my-event', (event: string, message?: any) => {
console.log(`{[Event] ${event}:`, message);
});
eventChannel.publish('my-event', {
message: 'test',
});
You may also build your own custom event channel by implementing the Channel Interface.