0.0.2 • Published 2 years ago

@trozlabs/pubsub v0.0.2

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

@trozlabs/pubsub

npm i @trozlabs/pubsub

Example listening and publishing to multiple pubsub services.

const pubsub = new PubSubClient({
    clients: [
        new GCPPubSubClient({
            topicId: 'DEV',
            subscriptionId: 'DEV',
            client: {
                projectId: 'developer-playground-328319',
                keyFilename: './_scratch/developer-playground.json'
            }
        }),
        new GCPPubSubClient({
            topicId: 'caseChanged',
            subscriptionId: 'caseChanged-sub',
            client: {
                projectId: 'testproject1953',
                keyFilename: './_scratch/testproject1953.json'
            }
        }),
        new StanzaClient({
            node: 'pubsub',
            client: {
                jid: 'user@xmpp.example.com',
                password: 'password',
                resource: 'users:123;abcdef',
                transports: {
                    websocket: 'wss://xmpp.example.com',
                    bosh: 'https://xmpp.example.com/http-bind/'
                }
            }
        })
    ],
    heartbeatEvent: {
        interval: 5000,
        env: config.env,
        debug: config.debug,
        service: config.service,
        hostname: config.hostname,
        port: config.port
    }
});

pubsub.on('message', function() {
    console.log('message', ...arguments);
});

pubsub.on('error', function() {
    console.log('error', ...arguments);
});

pubsub.publish({
    body: 'Hello to all services' 
});