Skip to content

Commit

Permalink
Merge pull request #236 from trackle-iot/allow-disabling-heartbeat
Browse files Browse the repository at this point in the history
fix: accept 0 for heartbeatIntervalInSeconds
  • Loading branch information
luddd3 committed May 4, 2022
2 parents 03de4c2 + 208af68 commit e3b46c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/AmqpConnectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ export default class AmqpConnectionManager extends EventEmitter implements IAmqp
this.connectionOptions = options.connectionOptions;

this.heartbeatIntervalInSeconds =
options.heartbeatIntervalInSeconds || HEARTBEAT_IN_SECONDS;
options.heartbeatIntervalInSeconds || options.heartbeatIntervalInSeconds === 0
? options.heartbeatIntervalInSeconds
: HEARTBEAT_IN_SECONDS;
this.reconnectTimeInSeconds =
options.reconnectTimeInSeconds || this.heartbeatIntervalInSeconds;

Expand Down
10 changes: 10 additions & 0 deletions test/AmqpConnectionManagerTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ describe('AmqpConnectionManager', function () {
expect(connection.url, 'connection.url').to.equal('amqp://localhost?heartbeat=5');
});

it('should establish a connection to a broker disabling heartbeat', async () => {
amqp = new AmqpConnectionManager('amqp://localhost', {
heartbeatIntervalInSeconds: 0,
});
amqp.connect();
const [{ connection, url }] = await once(amqp, 'connect');
expect(url, 'url').to.equal('amqp://localhost');
expect(connection.url, 'connection.url').to.equal('amqp://localhost?heartbeat=0');
});

it('should close connection to a broker', async () => {
amqp = new AmqpConnectionManager('amqp://localhost');
amqp.connect();
Expand Down

0 comments on commit e3b46c8

Please sign in to comment.