Skip to content

Commit c6b0300

Browse files
author
Tom Kirkpatrick
committed
fix: prevent startup if unable to connect to Rabbit
1 parent 2b46955 commit c6b0300

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,23 +39,26 @@ module.exports = function loopbackComponentMq(app, settings) {
3939
RabbitMQ.log = _.get(settings, 'options.log', console)
4040
RabbitMQ.log = typeof RabbitMQ.log === 'string' ? require(RabbitMQ.log) : RabbitMQ.log
4141

42+
// Handle the case where unable to connect to Rabbit.
4243
rabbit.on('unreachable', () => {
4344
RabbitMQ.log.error('Unable to connect to Rabbit')
44-
throw new Error('Unable to connect to Rabbit')
45+
process.exit(1)
4546
})
4647

4748
// Graceful shutdown.
4849
process.on('SIGINT', () => {
4950
debug('Caught SIGINT - performing graceful shutdown...')
5051
rabbit.shutdown()
51-
process.exit(0)
52+
process.exit(1)
5253
})
5354

5455
// Configure the rabbit topology.
5556
rabbit.configure(settings.topology)
5657
.then(() => debug('Rabbit topology configured'))
57-
.catch(err => RabbitMQ.log.error(err))
58-
58+
.catch(err => {
59+
RabbitMQ.log.error('Unable to configure Rabbit topology', err.cause)
60+
process.exit(1)
61+
})
5962

6063
const connection = rabbit.configurations.default.connection
6164
const parsedConnectionUri = url.parse(connection.uri)

0 commit comments

Comments
 (0)