How to use the nats.on function in nats

To help you get started, we’ve selected a few nats examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github JarvusInnovations / lapidus / src / plugins / nats.js View on Github external
init: function (config, eventEmitter) {
        console.log('Connecting to nats on: ' + config.servers.join(', '));
        nats = nats.connect(config);

        nats.on('error', function(err) {
           console.error('NATS: ' + err);
        });

        eventEmitter.on('event', function(event) {
            var subject,
                action,
                cachePrefix = config.cachePrefix;

            if (event.schema && event.table) {
                subject = event.schema + '.' + event.table + (event.pk ? ('.' + event.pk) : '');
            } else if (event.ns && event.pk) {
                subject = event.ns + '.' + event.pk;
            }

            nats.publish(subject, config.publishEventData ? JSON.stringify(event) : null);

nats

Node.js client for NATS, a lightweight, high-performance cloud native messaging system

Apache-2.0
Latest version published 2 months ago

Package Health Score

89 / 100
Full package analysis