diff --git a/lib/index.js b/lib/index.js index 27c5d8c..e7a9b4e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -19,8 +19,6 @@ module.exports = function loopbackComponentMq(app, config) { // Independent of app boot, add model and ACL setupModel(app) - // - Update models to work even if rabbit is not there/not booted - // Wait the app to be booted app.once('booted', () => { @@ -30,10 +28,11 @@ module.exports = function loopbackComponentMq(app, config) { // Get a reference to the configured datasource const dsName = _.get(app, 'settings.loopback-component-mq.options.dataSource', 'rabbit') const ds = app.dataSources[dsName] + const dsOptions = _.get(ds, 'settings.options') // If we have a datasource, wire up Rabbit and set up the topology - if (ds) { - Queue.rabbit = new Rabbit(ds.settings.options || {}) + if (ds && dsOptions) { + Queue.rabbit = new Rabbit(dsOptions) RabbitTopology.setupTopology(Queue) } diff --git a/lib/setup-model.js b/lib/setup-model.js index a89aa38..37e52de 100644 --- a/lib/setup-model.js +++ b/lib/setup-model.js @@ -1,5 +1,6 @@ const _ = require('lodash') const debug = require('debug')('loopback:component:mq') +const loopback = require('loopback') module.exports = function setupModelFn(app) { debug('setupModelFn') @@ -10,6 +11,10 @@ module.exports = function setupModelFn(app) { dataSource = app.dataSources[dataSource] } + if (!dataSource) { + dataSource = loopback.createDataSource({ connector: loopback.Memory }) + } + const newModel = dataSource.createModel('Queue', {}, { plural: 'Queue', base: 'Model',