@@ -28,10 +28,11 @@ type DefaultBus struct {
28
28
Outbox TxOutbox
29
29
PrefetchCount uint
30
30
AmqpConnStr string
31
- amqpConn * amqp.Connection
31
+ ingressConn * amqp.Connection
32
+ egressConn * amqp.Connection
32
33
workers []* worker
33
- AMQPChannel * amqp.Channel
34
- outAMQPChannel * amqp.Channel
34
+ ingressChannel * amqp.Channel
35
+ egressChannel * amqp.Channel
35
36
serviceQueue amqp.Queue
36
37
rpcQueue amqp.Queue
37
38
SvcName string
@@ -83,7 +84,7 @@ func (b *DefaultBus) createRPCQueue() (amqp.Queue, error) {
83
84
*/
84
85
uid := xid .New ().String ()
85
86
qName := b .SvcName + "_rpc_" + uid
86
- q , e := b .AMQPChannel .QueueDeclare (qName ,
87
+ q , e := b .ingressChannel .QueueDeclare (qName ,
87
88
false , /*durable*/
88
89
true , /*autoDelete*/
89
90
false , /*exclusive*/
@@ -97,7 +98,7 @@ func (b *DefaultBus) createServiceQueue() (amqp.Queue, error) {
97
98
var q amqp.Queue
98
99
99
100
if b .PurgeOnStartup {
100
- msgsPurged , purgeError := b .AMQPChannel .QueueDelete (qName , false /*ifUnused*/ , false /*ifEmpty*/ , false /*noWait*/ )
101
+ msgsPurged , purgeError := b .ingressChannel .QueueDelete (qName , false /*ifUnused*/ , false /*ifEmpty*/ , false /*noWait*/ )
101
102
if purgeError != nil {
102
103
b .Log ().WithError (purgeError ).WithField ("deleted_messages" , msgsPurged ).Error ("failed to purge queue" )
103
104
return q , purgeError
@@ -108,7 +109,7 @@ func (b *DefaultBus) createServiceQueue() (amqp.Queue, error) {
108
109
if b .DLX != "" {
109
110
args ["x-dead-letter-exchange" ] = b .DLX
110
111
}
111
- q , e := b .AMQPChannel .QueueDeclare (qName ,
112
+ q , e := b .ingressChannel .QueueDeclare (qName ,
112
113
true , /*durable*/
113
114
false , /*autoDelete*/
114
115
false , /*exclusive*/
@@ -124,7 +125,7 @@ func (b *DefaultBus) createServiceQueue() (amqp.Queue, error) {
124
125
func (b * DefaultBus ) bindServiceQueue () error {
125
126
126
127
if b .deadletterHandler != nil && b .DLX != "" {
127
- err := b .AMQPChannel .ExchangeDeclare (b .DLX , /*name*/
128
+ err := b .ingressChannel .ExchangeDeclare (b .DLX , /*name*/
128
129
"fanout" , /*kind*/
129
130
true , /*durable*/
130
131
false , /*autoDelete*/
@@ -144,7 +145,7 @@ func (b *DefaultBus) bindServiceQueue() error {
144
145
for _ , subscription := range b .DelayedSubscriptions {
145
146
topic := subscription [0 ]
146
147
exchange := subscription [1 ]
147
- e := b .AMQPChannel .ExchangeDeclare (exchange , /*name*/
148
+ e := b .ingressChannel .ExchangeDeclare (exchange , /*name*/
148
149
"topic" , /*kind*/
149
150
true , /*durable*/
150
151
false , /*autoDelete*/
@@ -178,27 +179,32 @@ func (b *DefaultBus) Start() error {
178
179
179
180
var e error
180
181
//create amqo connection and channel
181
- if b .amqpConn , e = b .connect (MaxRetryCount ); e != nil {
182
+ if b .ingressConn , e = b .connect (MaxRetryCount ); e != nil {
183
+ return e
184
+ }
185
+ if b .egressConn , e = b .connect (MaxRetryCount ); e != nil {
182
186
return e
183
187
}
184
188
185
- if b .AMQPChannel , e = b .createAMQPChannel (b .amqpConn ); e != nil {
189
+ if b .ingressChannel , e = b .createAMQPChannel (b .ingressConn ); e != nil {
186
190
return e
187
191
}
188
- if b .outAMQPChannel , e = b .createAMQPChannel (b .amqpConn ); e != nil {
192
+ if b .egressChannel , e = b .createAMQPChannel (b .egressConn ); e != nil {
189
193
return e
190
194
}
191
195
192
196
//register on failure notifications
193
197
b .amqpErrors = make (chan * amqp.Error )
194
198
b .amqpBlocks = make (chan amqp.Blocking )
195
- b .amqpConn .NotifyClose (b .amqpErrors )
196
- b .amqpConn .NotifyBlocked (b .amqpBlocks )
197
- b .outAMQPChannel .NotifyClose (b .amqpErrors )
199
+ b .ingressConn .NotifyClose (b .amqpErrors )
200
+ b .ingressConn .NotifyBlocked (b .amqpBlocks )
201
+ b .egressConn .NotifyClose (b .amqpErrors )
202
+ b .egressConn .NotifyBlocked (b .amqpBlocks )
203
+ b .egressChannel .NotifyClose (b .amqpErrors )
198
204
//TODO:Figure out what should be done
199
205
200
206
//init the outbox that sends the messages to the amqp transport and handles publisher confirms
201
- if e := b .Outgoing .init (b .outAMQPChannel , b .Confirm , true ); e != nil {
207
+ if e := b .Outgoing .init (b .egressChannel , b .Confirm , true ); e != nil {
202
208
return e
203
209
}
204
210
/*
@@ -208,7 +214,7 @@ func (b *DefaultBus) Start() error {
208
214
if b .IsTxnl {
209
215
210
216
var amqpChan * amqp.Channel
211
- if amqpChan , e = b .createAMQPChannel (b .amqpConn ); e != nil {
217
+ if amqpChan , e = b .createAMQPChannel (b .egressConn ); e != nil {
212
218
b .Log ().WithError (e ).Error ("failed to create amqp channel for transactional outbox" )
213
219
return e
214
220
}
@@ -269,7 +275,7 @@ func (b *DefaultBus) createBusWorkers(workerNum uint) ([]*worker, error) {
269
275
workers := make ([]* worker , 0 )
270
276
for i := uint (0 ); i < workerNum ; i ++ {
271
277
//create a channel per worker as we can't share channels across go routines
272
- amqpChan , createChanErr := b .createAMQPChannel (b .amqpConn )
278
+ amqpChan , createChanErr := b .createAMQPChannel (b .ingressConn )
273
279
if createChanErr != nil {
274
280
return nil , createChanErr
275
281
}
@@ -681,7 +687,7 @@ func (b *DefaultBus) registerHandlerImpl(exchange, routingKey string, msg Messag
681
687
}
682
688
683
689
func (b * DefaultBus ) bindQueue (topic , exchange string ) error {
684
- return b .AMQPChannel .QueueBind (b .serviceQueue .Name , topic , exchange , false /*noWait*/ , nil /*args*/ )
690
+ return b .ingressChannel .QueueBind (b .serviceQueue .Name , topic , exchange , false /*noWait*/ , nil /*args*/ )
685
691
}
686
692
687
693
type rpcPolicy struct {
0 commit comments