@@ -12,6 +12,16 @@ module.exports = function rabbitTopology() {
1212    msqQueue  =  QueueModel . rabbit . exchange . queue ( {  name,  durable : true  } ) 
1313  } 
1414
15+   function  setupQueues ( Model )  { 
16+     QueueModel  =  Model 
17+ 
18+     // Loop through all the defined queues 
19+     _ . forEach ( QueueModel . topology ,  ( handlers ,  queue )  =>  { 
20+       // Setup the actual queue on RabbitMQ 
21+       setupQueue ( queue ) 
22+     } ) 
23+   } 
24+ 
1525  function  setupQueueConsumer ( app ,  queue ,  definition )  { 
1626    debug ( 'setupQueueConsumer' ) 
1727    const  modelName  =  definition . model 
@@ -31,7 +41,10 @@ module.exports = function rabbitTopology() {
3141    } 
3242
3343    // Start consuming the queue 
34-     msqQueue . consume ( Method ) 
44+     if  ( msqQueue )  { 
45+       msqQueue . consume ( Method ) 
46+     } 
47+ 
3548
3649    debug ( 'setupQueueConsumer: queue: %s, model: %s, method: %s' ,  queue ,  modelName ,  methodName ) 
3750  } 
@@ -49,7 +62,12 @@ module.exports = function rabbitTopology() {
4962
5063    Model [ methodName ]  =  function  queueProducer ( params )  { 
5164      debug ( `${ modelName } ${ methodName }  ,  params ) 
52-       QueueModel . rabbit . exchange . publish ( params ,  {  key : queue  } ) 
65+       if  ( QueueModel . rabbit  &&  QueueModel . rabbit . exchange )  { 
66+         QueueModel . rabbit . exchange . publish ( params ,  {  key : queue  } ) 
67+       } 
68+       else  { 
69+         debug ( 'setupQueueProducer: queue %s is not yet initialised' ,  queue ) 
70+       } 
5371    } 
5472  } 
5573
@@ -59,9 +77,6 @@ module.exports = function rabbitTopology() {
5977    // Loop through all the defined queues 
6078    _ . forEach ( QueueModel . topology ,  ( handlers ,  queue )  =>  { 
6179
62-       // Setup the actual queue on RabbitMQ 
63-       setupQueue ( queue ) 
64- 
6580      // Setup the consumer of this queue 
6681      if  ( handlers . consumer )  { 
6782        setupQueueConsumer ( QueueModel . app ,  queue ,  handlers . consumer ) 
@@ -77,6 +92,7 @@ module.exports = function rabbitTopology() {
7792
7893  return  { 
7994    setupQueue, 
95+     setupQueues, 
8096    setupTopology, 
8197    setupQueueProducer, 
8298    setupQueueConsumer, 
0 commit comments