When connecting to RabbitMQ via amqplib, the value of the Heartbeat parameter cannot be set.
I do this:
// NPM Modules
const amqp = require('amqplib/callback_api');
const withAutoRecovery = require('amqplib-auto-recovery');
// Application configuration
const config = settings.getConfig();
withAutoRecovery(amqp, {
onError: (err) => { console.log(err.message); },
isErrorUnrecoverable: (err) => { console.log(err) }
}).connect(config.rabbitmq, (err, connection) => {
// If there are connection errors
if (err) {
console.error(this.conn_str_amqp);
console.error('[AMQP] Connection error:', err.message);
} else if (connection) {
// Connection Error Event
connection.on('error', (err) => {
if (err.message !== 'Connection closing') {
console.error('[AMQP] Closing connection', err.message);
}
});
// Error event when you close the connection
connection.on('close', () => {
console.error('[AMQP] Closing connection');
});
// Hint to user
console.log('[AMQP] Connected');
}
});
Here config.rabbitmq is:
{
protocol: 'amqp',
hostname: 'localhost',
port: 5672,
username: 'guest',
password: 'guest',
locale: 'en_US',
frameMax: 0x1000,
heartbeat: 1800,
vhost: '/',
}
I expect to get the Heartbeat = 1800s parameter value, in the UI Managment window the default value Heartbeat = 60s is displayed.
I tried to pass another object instead config.rabbitmq line (https://www.rabbitmq.com/uri-spec.html and https://www.rabbitmq.com/uri-query-parameters.html) in the format:
function getRabbitMQConnectionString() {
const rabbitmq = config.rabbitmq;
return `${rabbitmq.protocol}://${rabbitmq.username}:${rabbitmq.password}@${rabbitmq.hostname}:${rabbitmq.port}${encodeURIComponent(rabbitmq.vhost)}?heartbeat=${rabbitmq.heartbeat}`;
}
Thus, too, it turned out similar to the above effect.
Tell me, please, how to correctly set the Heartbeat parameter through the Node.js client application on amqplib?