@@ -21,10 +21,8 @@ class ServiceSubRabbit extends ServiceSub {
21
21
22
22
this . maxAttempts = this . config . default ( "service.rabbit.maxAttempts" , 5 ) ;
23
23
this . retryDelay = this . config . default ( "service.rabbit.retryDelay" , 5000 ) ;
24
- this . expireTime = this . config . default ( "service.rabbit.expireTime" , 1000 * 60 * 60 * 24 ) ; // 1 day
25
24
this . remainingAttempts = this . maxAttempts - 1 ;
26
25
27
- this . _withExpire = true ;
28
26
this . _status = "ok" ;
29
27
this . _initializing = false ;
30
28
this . _connection = null ;
@@ -37,9 +35,8 @@ class ServiceSubRabbit extends ServiceSub {
37
35
}
38
36
39
37
* initialize ( ) {
40
- if ( this . amqp . getConnection ( ) ) {
38
+ if ( this . amqp . getConnection ( ) )
41
39
this . init ( ) ;
42
- }
43
40
}
44
41
45
42
* init ( ) {
@@ -98,28 +95,7 @@ class ServiceSubRabbit extends ServiceSub {
98
95
let channel = this . _channels [ event ] ;
99
96
let queueName = `${ this . _namespace } .${ this . SERVICE_NAME } .${ event } ` ;
100
97
101
- const queueOpts = {
102
- durable : true ,
103
- } ;
104
-
105
- if ( this . _withExpire ) {
106
- Object . assign ( queueOpts , { expires : this . expireTime } ) ;
107
- }
108
-
109
- // by default, assert queue with `expires` header. if queue is exists and
110
- // don't have `expires` header, rabbitMQ will throw an error and close channel.
111
- // we catch the error on `close` or `error` emit (amqp.node lib emit those error)
112
- // and re-init this class
113
- try {
114
- yield channel . assertQueue ( queueName , queueOpts ) ;
115
- } catch ( e ) {
116
- this . _initializing = false ;
117
-
118
- // dont use `expires` header on re-init
119
- this . _withExpire = false ;
120
- this . _connection . on ( "close" , this . init . bind ( this ) ) ;
121
- this . _connection . on ( "error" , this . init . bind ( this ) ) ;
122
- }
98
+ yield channel . assertQueue ( queueName , { durable : true } ) ;
123
99
124
100
channel . consume ( queueName , async ( function * ( message ) {
125
101
try {
@@ -144,29 +120,7 @@ class ServiceSubRabbit extends ServiceSub {
144
120
let queueName = this . _namespace + "." + publisherName + "." + this . SERVICE_NAME + "." + event ;
145
121
let exchangeName = this . _namespace + "." + publisherName + "." + event ;
146
122
147
- const queueOpts = {
148
- durable : true ,
149
- } ;
150
-
151
- if ( this . _withExpire ) {
152
- Object . assign ( queueOpts , { expires : this . expireTime } ) ;
153
- }
154
-
155
- // by default, assert queue with `expires` header. if queue is exists and
156
- // don't have `expires` header, rabbitMQ will throw an error and close channel.
157
- // we catch the error on `close` or `error` emit (amqp.node lib emit those error)
158
- // and re-init this class
159
- try {
160
- yield channel . assertQueue ( queueName , queueOpts ) ;
161
- } catch ( e ) {
162
- this . _initializing = false ;
163
-
164
- // dont use `expires` header on re-init
165
- this . _withExpire = false ;
166
- this . _connection . on ( "close" , this . init . bind ( this ) ) ;
167
- this . _connection . on ( "error" , this . init . bind ( this ) ) ;
168
- }
169
-
123
+ yield channel . assertQueue ( queueName , { durable : true } ) ;
170
124
yield channel . assertExchange ( exchangeName , "fanout" , { durable : true } ) ;
171
125
yield channel . bindQueue ( queueName , exchangeName , "" ) ;
172
126
this . _queues . push ( queueName ) ;
@@ -215,12 +169,12 @@ class ServiceSubRabbit extends ServiceSub {
215
169
retryDelay : this . retryDelay ,
216
170
retryStrategy : this . retryStrategy . bind ( this ) ,
217
171
fullResponse : false
218
- } ;
172
+ }
219
173
220
174
if ( this . _secret != null ) {
221
175
jsonBody [ "headers" ] = {
222
176
"Authorization" : `Bearer ${ this . _secret } `
223
- } ;
177
+ }
224
178
}
225
179
226
180
response = yield request ( jsonBody ) ;
0 commit comments