File tree 2 files changed +36
-1
lines changed
2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ module.exports = function loopbackComponentMq(app, config) {
22
22
// Get a reference to the created model and set up the topology
23
23
const Queue = app . models . Queue
24
24
25
- RabbitTopology . setupTopology ( Queue )
25
+ RabbitTopology . stubQueueMethod ( Queue )
26
26
27
27
// Wait the app to be booted
28
28
app . once ( 'booted' , ( ) => {
@@ -36,6 +36,7 @@ module.exports = function loopbackComponentMq(app, config) {
36
36
if ( ds && dsOptions ) {
37
37
Queue . rabbit = new Rabbit ( dsOptions )
38
38
RabbitTopology . setupQueues ( Queue )
39
+ RabbitTopology . setupTopology ( Queue )
39
40
}
40
41
41
42
} )
Original file line number Diff line number Diff line change @@ -90,11 +90,45 @@ module.exports = function rabbitTopology() {
90
90
} )
91
91
}
92
92
93
+ function stubQueueMethod ( StubmodelModel ) {
94
+ // Loop through all the defined queues
95
+ _ . forEach ( StubmodelModel . topology , handlers => {
96
+
97
+
98
+ // Setup the consumer of this queue
99
+ if ( handlers . consumer ) {
100
+ const modelName = handlers . consumer . model
101
+ const methodName = handlers . consumer . method
102
+ const Model = StubmodelModel . app . models [ modelName ]
103
+
104
+ // Log if the method does not exists yet
105
+ Model [ methodName ] = function stubQueueConsumer ( ) {
106
+ debug ( `${ modelName } .${ methodName } is not initialised yet` )
107
+ }
108
+ }
109
+
110
+ // Setup the producers of this queue
111
+ if ( handlers . producer ) {
112
+ const modelName = handlers . producer . model
113
+ const methodName = handlers . producer . method
114
+ const Model = StubmodelModel . app . models [ modelName ]
115
+
116
+ // Log if the method does not exists yet
117
+ Model [ methodName ] = function stubQueueProducer ( ) {
118
+ debug ( `${ modelName } .${ methodName } is not initialised yet` )
119
+ }
120
+ }
121
+
122
+ } )
123
+
124
+ }
125
+
93
126
return {
94
127
setupQueue,
95
128
setupQueues,
96
129
setupTopology,
97
130
setupQueueProducer,
98
131
setupQueueConsumer,
132
+ stubQueueMethod,
99
133
}
100
134
}
You can’t perform that action at this time.
0 commit comments