Open Fbernardpro opened 4 years ago
i didn't reach to attach the source code. Please find it below :
process.env.AMQ_SERVERS=server1;server2 server1, server2 : managed by cluster
config.js 'use strict';
const queueTest = process.env.AMQ_TEST_CONSUME_PRIVATE || 'fb.test.consume.private'; const rabbitMqProtocol = process.env.AMQ_PROTOCOL || 'amqp'; const rabbitMqUser = process.env.AMQ_USER || false; const rabbitMqPassword = process.env.AMQ_PASSWORD || false; const rabbitMqServers = process.env.AMQ_SERVERS || '';
const connections = rabbitMqServers.split(';').map(server => ${rabbitMqProtocol}://${rabbitMqUser}:${rabbitMqPassword}@${server}:5672//?heartbeat=10
);
const exchanges = {};
exchanges[queueTest] = { type: 'direct', };
module.exports = { vhosts: { ' / ': { connection: { retry: { min: 1000, max: 60000, factor: 2, strategy: 'exponential', }, }, connectionStrategy: 'random', connections, exchanges, queues: [ queueTest, ], bindings: { bindingTest: { source: queueTest, destination: queueTest, destinationType: 'queue', bindingKey: 'private_key', }, }, publications: { demoPublish: { exchange: queueTest, routingKey: 'private_key', }, }, subscriptions: { demoConsume: { queue: queueTest, }, }, }, }, };
index.js 'use strict';
const rascal = require('rascal'); const Broker = require('rascal').BrokerAsPromised; const definitions = require('../../config/configRascal');
const config = rascal.withDefaultConfig(definitions); const consumer = require('./executeMessage'); const log = require('../../config/logger.js');
module.exports = (async () => { try { const broker = await Broker.create(config); log.debug('Rascal listener initialized --------------'); broker.on(' error ', (errBroker) => { log.error('Broker error', errBroker); }); log.debug('Rascal listener running fine --------------');
// Consume a message
const subscription = await broker.subscribe('demoConsume', { prefetch: 10, retry: { delay: 10000 } });
subscription.on('message', (message, content, ackOrNack) => {
log.debug('message reçu :', message);
ackOrNack();
consumer(message);
}).on('error', (err) => {
log.error('Subscriber error', err);
}).on('invalid_content', (err, content, ackOrNack) => {
log.error('Invalid content', err);
ackOrNack(err);
}).on(' redeliveries_exceeded ', (err, message, ackOrNack) => {
log.error(' Redeliveries exceeded ', err);
ackOrNack(err);
});
} catch (err) { log.debug('Connexion error -------- '); log.error(err); } });
Hi, i would like ceate a nodejs script with rascal api, which is listening a queue and automatiquely reconnect to a RabbitMq server after a Rabbit shutdown or after switch to another server (cluster). For that i writed scripts in attachements, based on the Rascal documentations. My configuration : rabbit server cluster of 2 servers rabbitMq 3.7.5 javascript nodejs with rascal api : 4.7.0
But when i test the shutdown i have this message :
[2020-03-11T17:13:28.941Z] DEBUG: psf-ms-rascal-1.0.0/15684 on SCU48652 (L:\psf-ms-rascal\src\amq\listeners\index.js:15 in module.exports): Rascal listener initialized -------------- [2020-03-11T17:13:28.943Z] DEBUG: psf-ms-rascal-1.0.0/15684 on SCU48652 (L:\psf-ms-rascal\src\amq\listeners\index.js:19 in module.exports): Rascal listener running fine -------------- events.js:183 throw er; // Unhandled 'error' event
Error: read ECONNRESET at _errnoException (util.js:1024:11) at TCP.onread (net.js:615:25) [nodemon] app crashed - waiting for file changes before starting...
And when i start rabbitmq again , it doesn't reconnect automatiquely.
I dont know how i can fix simply this issue. Thank you for your Help.