How to use the nats.REQ_TIMEOUT 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 hemerajs / hemera / packages / hemera / lib / index.js View on Github external
_sendRequestHandler(response) {
    const self = this

    if (response.code && response.code === NATS.REQ_TIMEOUT) {
      self._timeoutHandler()
      return
    }

    const res = self._clientDecoder(response)
    self.response.payload = res.value
    self.response.error = res.error

    // decoding error
    if (self.response.error) {
      const internalError = new Errors.ParseError('Client payload decoding', self.errorDetails).causedBy(
        self.response.error
      )
      self.log.error(internalError)
      self._execute(self.response.error)
      return
github nats-io / stan.js / lib / stan.js View on Github external
sc.nc.requestOne(reqSubject, Buffer.from(ur.serializeBinary()), sc.options.connectTimeout, (msg) => {
        let err;
        if (msg instanceof nats.NatsError) {
            const type = doClose ? CLOSE_REQ_TIMEOUT : UNSUB_REQ_TIMEOUT;
            err = new nats.NatsError(type, type, msg);
            if (msg.code === nats.REQ_TIMEOUT) {
                this.emit('timeout', err);
            } else {
                this.emit('error', err);
            }
            return;
        }
        //noinspection JSUnresolvedVariable
        const r = proto.pb.SubscriptionResponse.deserializeBinary(Buffer.from(msg, 'binary'));
        err = r.getError();
        if (err && err.length > 0) {
            this.emit('error', new Error(r.getError()));
        } else {
            this.emit(doClose ? 'closed' : 'unsubscribed');
        }
    });
};
github moorara / microservices-demo / services / graphql / src / services / asset.js View on Github external
this.conn.requestOne(subject, JSON.stringify(request), {}, timeout, resp => {
      if (resp instanceof nats.NatsError && resp.code === nats.REQ_TIMEOUT) {
        return callback(resp)
      }

      let response

      try {
        response = JSON.parse(resp)
      } catch (err) {
        return callback(err)
      }

      if (response.kind !== request.kind) {
        return callback(new Error(`Invalid response ${response.kind}`))
      }

      callback(null, response)

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

89 / 100
Full package analysis