How to use the nats.createInbox 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 nats-io / stan.js / lib / stan.js View on Github external
Stan.prototype.subscribe = function(subject, qGroup, options) {
    const args = {};
    if (typeof qGroup === 'string') {
        args.qGroup = qGroup;
    } else if (typeof qGroup === 'object') {
        args.options = qGroup;
    }
    if (typeof options === 'object') {
        args.options = options;
    }
    if (!args.options) {
        args.options = new SubscriptionOptions();
    }

    // in node-nats there's no Subscription object...
    const retVal = new Subscription(this, subject, args.qGroup, nats.createInbox(), args.options, args.callback);

    if (typeof subject !== 'string' || subject.length === 0) {
        process.nextTick(() => {
            retVal.emit('error', new Error(BAD_SUBJECT));
        });
        return retVal;
    }

    if (this.isClosed()) {
        process.nextTick(() => {
            retVal.emit('error', new Error(CONN_CLOSED));
        });
        return retVal;
    }

    this.subMap[retVal.inbox] = retVal;
github nats-io / stan.js / lib / stan.js View on Github external
this.nc.on('connect', () => {
        // heartbeat processing
        const hbInbox = nats.createInbox();
        this.hbSubscription = this.nc.subscribe(hbInbox, (msg, reply) => {
            this.nc.publish(reply);
        });

        this.pingInbox = nats.createInbox();
        this.pingSubscription = this.nc.subscribe(this.pingInbox, (msg) => {
            if (msg) {
                const pingResponse = proto.pb.PingResponse.deserializeBinary(Buffer.from(msg, 'binary'));
                const err = pingResponse.getError();
                if (err) {
                    this.closeWithError('connection_lost', err);
                    return;
                }
            }
            this.pingOut = 0;
        });

        this.ackSubscription = this.nc.subscribe(this.ackSubject, this.processAck());

        const discoverSubject = this.options.discoverPrefix + '.' + this.clusterID;
        //noinspection JSUnresolvedFunction
github nats-io / stan.js / lib / stan.js View on Github external
this.nc.on('connect', () => {
        // heartbeat processing
        const hbInbox = nats.createInbox();
        this.hbSubscription = this.nc.subscribe(hbInbox, (msg, reply) => {
            this.nc.publish(reply);
        });

        this.pingInbox = nats.createInbox();
        this.pingSubscription = this.nc.subscribe(this.pingInbox, (msg) => {
            if (msg) {
                const pingResponse = proto.pb.PingResponse.deserializeBinary(Buffer.from(msg, 'binary'));
                const err = pingResponse.getError();
                if (err) {
                    this.closeWithError('connection_lost', err);
                    return;
                }
            }
            this.pingOut = 0;
        });

nats

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

Apache-2.0
Latest version published 4 months ago

Package Health Score

86 / 100
Full package analysis