mirror of
https://github.com/go-micro/go-micro.git
synced 2025-11-29 21:47:44 +02:00
Repair mq asynchronous send, mq write failure without error output (#2191)
* Update http.go Exit before deregister is executed * Create http.go Exit before deregister is executed * Solve the problem that the resources have not been fully released due to early exit * Optimize some code * Optimize some code * Optimize some code * fix service default logger * Repair mq asynchronous send, mq write failure without error output * Repair mq asynchronous send, mq write failure without error output
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/asim/go-micro/logger"
|
||||
"github.com/streadway/amqp"
|
||||
)
|
||||
|
||||
@@ -125,10 +126,37 @@ func (r *rabbitMQConn) reconnect(secure bool, config *amqp.Config) {
|
||||
connect = true
|
||||
notifyClose := make(chan *amqp.Error)
|
||||
r.Connection.NotifyClose(notifyClose)
|
||||
chanNotifyClose := make(chan *amqp.Error)
|
||||
channel := r.ExchangeChannel.channel
|
||||
channel.NotifyClose(chanNotifyClose)
|
||||
channelNotifyReturn := make(chan amqp.Return)
|
||||
channel.NotifyReturn(channelNotifyReturn)
|
||||
|
||||
// block until closed
|
||||
select {
|
||||
case <-notifyClose:
|
||||
case result, ok := <-channelNotifyReturn:
|
||||
if !ok {
|
||||
// Channel closed, probably also the channel or connection.
|
||||
return
|
||||
}
|
||||
// Do what you need with messageFailing.
|
||||
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
|
||||
logger.Errorf("notify error reason: %s, description: %s", result.ReplyText, result.Exchange)
|
||||
}
|
||||
case err := <-chanNotifyClose:
|
||||
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
|
||||
logger.Error(err)
|
||||
}
|
||||
// block all resubscribe attempt - they are useless because there is no connection to rabbitmq
|
||||
// create channel 'waitConnection' (at this point channel is nil or closed, create it without unnecessary checks)
|
||||
r.Lock()
|
||||
r.connected = false
|
||||
r.waitConnection = make(chan struct{})
|
||||
r.Unlock()
|
||||
case err := <-notifyClose:
|
||||
if logger.V(logger.ErrorLevel, logger.DefaultLogger) {
|
||||
logger.Error(err)
|
||||
}
|
||||
// block all resubscribe attempt - they are useless because there is no connection to rabbitmq
|
||||
// create channel 'waitConnection' (at this point channel is nil or closed, create it without unnecessary checks)
|
||||
r.Lock()
|
||||
|
||||
Reference in New Issue
Block a user