Skip to content

Commit

Permalink
fix: prevent startup if unable to connect to Rabbit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Kirkpatrick committed Jan 16, 2017
1 parent 2b46955 commit c6b0300
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,23 +39,26 @@ module.exports = function loopbackComponentMq(app, settings) {
RabbitMQ.log = _.get(settings, 'options.log', console)
RabbitMQ.log = typeof RabbitMQ.log === 'string' ? require(RabbitMQ.log) : RabbitMQ.log

// Handle the case where unable to connect to Rabbit.
rabbit.on('unreachable', () => {
RabbitMQ.log.error('Unable to connect to Rabbit')
throw new Error('Unable to connect to Rabbit')
process.exit(1)
})

// Graceful shutdown.
process.on('SIGINT', () => {
debug('Caught SIGINT - performing graceful shutdown...')
rabbit.shutdown()
process.exit(0)
process.exit(1)
})

// Configure the rabbit topology.
rabbit.configure(settings.topology)
.then(() => debug('Rabbit topology configured'))
.catch(err => RabbitMQ.log.error(err))

.catch(err => {
RabbitMQ.log.error('Unable to configure Rabbit topology', err.cause)
process.exit(1)
})

const connection = rabbit.configurations.default.connection
const parsedConnectionUri = url.parse(connection.uri)
Expand Down

0 comments on commit c6b0300

Please sign in to comment.