New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

node-nats-streaming-buffered-client

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-nats-streaming-buffered-client - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

49

dist/node-nats-streaming-buffered-client.js

@@ -54,5 +54,7 @@ "use strict";

*/
function NatsBufferedClient(bufferSize) {
function NatsBufferedClient(bufferSize, reconnectTimeout) {
if (bufferSize === void 0) { bufferSize = 10; }
if (reconnectTimeout === void 0) { reconnectTimeout = 30000; }
var _this = this;
this.reconnectTimeout = reconnectTimeout;
/**

@@ -71,3 +73,3 @@ * Indicates if we're processing the buffer

*/
this.connected = false;
this.clientConnected = false;
// Initialize our ring buffer with the requested size

@@ -128,2 +130,36 @@ //

}
Object.defineProperty(NatsBufferedClient.prototype, "connected", {
/**
* The getter for the client connection state
*
* @readonly
* @memberof NatsBufferedClient
*/
get: function () {
return this.clientConnected;
},
/**
* The setter for the client connection state
* Will stop or reset the client reconnect timer
*
* @memberof NatsBufferedClient
*/
set: function (newConnectedState) {
var _this = this;
this.clientConnected = newConnectedState;
console.log('[NATS-BUFFERED-CLIENT] Client connected status', this.clientConnected);
// This timer will try to reconnect to the server on prolonged absence
//
clearInterval(this.reconnectTimer);
if (!this.clientConnected) {
console.log('[NATS-BUFFERED-CLIENT] Starting reconnect timer', this.reconnectTimeout);
this.reconnectTimer = setInterval(function () {
console.log('[NATS-BUFFERED-CLIENT] Timer triggered reconnect...');
_this.reconnect();
}, this.reconnectTimeout);
}
},
enumerable: true,
configurable: true
});
/**

@@ -151,4 +187,9 @@ * Connect to the NATS server

case 3:
// Reset connected state
//
this.connected = false;
this.stan = undefined;
// Connect to NATS server
//
console.log('[NATS-BUFFERED-CLIENT] Connecting...');
this.stan = nats.connect(clusterId, clientId, options);

@@ -171,3 +212,2 @@ // Store connection parameters

console.error('[NATS-BUFFERED-CLIENT] Server error', error);
_this.reconnect();
});

@@ -206,3 +246,3 @@ this.stan.on('disconnect', function () {

//
console.log('[NATS-BUFFERED-CLIENT] Not connected so no need to disconnect', _this.connected, _this.stan);
console.log('[NATS-BUFFERED-CLIENT] Not connected so no need to disconnect', _this.connected, _this.stan === undefined);
resolve();

@@ -218,2 +258,3 @@ }

NatsBufferedClient.prototype.reconnect = function () {
console.log('[NATS-BUFFERED-CLIENT] Reconnecting...');
this.connect(this.clusterId, this.clientId, this.clientOptions);

@@ -220,0 +261,0 @@ };

@@ -9,2 +9,3 @@ import * as nats from 'node-nats-streaming';

export declare class NatsBufferedClient {
private reconnectTimeout;
/**

@@ -63,4 +64,25 @@ * The connection to the NATS server

*/
private connected;
private clientConnected;
/**
* The reconnect timer
*
* @private
* @type {NodeJS.Timer}
* @memberof NatsBufferedClient
*/
private reconnectTimer;
/**
* The getter for the client connection state
*
* @readonly
* @memberof NatsBufferedClient
*/
/**
* The setter for the client connection state
* Will stop or reset the client reconnect timer
*
* @memberof NatsBufferedClient
*/
connected: boolean;
/**
* Creates an instance of NatsBufferedClient

@@ -72,3 +94,3 @@ *

*/
constructor(bufferSize?: number);
constructor(bufferSize?: number, reconnectTimeout?: number);
/**

@@ -75,0 +97,0 @@ * Connect to the NATS server

10

package.json
{
"name": "node-nats-streaming-buffered-client",
"version": "1.0.0",
"version": "1.1.0",
"description": "",

@@ -71,4 +71,4 @@ "keywords": [],

"devDependencies": {
"@types/jest": "^23.1.3",
"@types/node": "^10.5.1",
"@types/jest": "^23.1.4",
"@types/node": "^10.5.2",
"colors": "^1.3.0",

@@ -80,3 +80,3 @@ "commitizen": "^2.10.1",

"husky": "^0.14.3",
"jest": "^23.2.0",
"jest": "^23.3.0",
"lint-staged": "^7.2.0",

@@ -94,3 +94,3 @@ "lodash.camelcase": "^4.3.0",

"rollup-plugin-typescript2": "^0.15.1",
"semantic-release": "^15.6.1",
"semantic-release": "^15.6.3",
"ts-jest": "^23.0.0",

@@ -97,0 +97,0 @@ "ts-node": "^7.0.0",

@@ -28,8 +28,12 @@ # NATS Streaming Buffered Client

// Initialize a client with a buffer of 2000 messages
// The default reconnect timeout is 30s but can be changed
//
const client = new NatsBufferedClient( 2000 );
const bufferSize = 2000;
const reconnectTimeout = 30000;
const client = new NatsBufferedClient( bufferSize, reconnectTimeout );
// Connect to the NATS server
//
client.connect( 'test-cluster', 'test' );
const natsOptions = { ... };
client.connect( 'test-cluster', 'test', natsOptions );

@@ -36,0 +40,0 @@ // Add a message to the buffer for publishing

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc