Skip to content

How to keep the connection open and also set connection timeout? #134

@shubsaini09

Description

@shubsaini09

Hello,

I have a huge traffic for my API and I feel making a connection for each request is not right. I want to know if there is way to keep the connection open or some sort of pooling is available in the library. Below is my sample code where the function conn is called on each request.

function conn() {
       ............
       ............
	const failover = new stompit.ConnectFailover(servers, reconnectOptions);
	failover.connect((error, client) => {
		if (error) {
			throw new Error(error);
		}
		const frame = client.send(sendHeaders);
		frame.write('my message');
		frame.end();
		client.disconnect();
		return 'success';
	});
}

Also, how do we set a connection timeout? I want to throw an error if the connection is taking long to establish. The default is 3000 but it does not work. I even tried setting it up separately and even that did not work.

my config is as below

{
	host,
	connectHeaders: {
		login,
		passcode,
	},
	ssl: true,
	port: 61614,
	timeout: 10000
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions