mirror of
https://github.com/oarkflow/mq.git
synced 2025-09-26 20:11:16 +08:00
update
This commit is contained in:
12
consumer.go
12
consumer.go
@@ -202,7 +202,13 @@ func (c *Consumer) OnClose(_ context.Context, _ net.Conn) error {
|
||||
}
|
||||
|
||||
func (c *Consumer) OnError(_ context.Context, conn net.Conn, err error) {
|
||||
fmt.Println("Error reading from connection:", err, conn.RemoteAddr())
|
||||
if c.isConnectionClosed(err) {
|
||||
log.Printf("Connection to broker closed for consumer %s at %s", c.id, conn.RemoteAddr())
|
||||
// Trigger reconnection if possible
|
||||
c.reconnectCh <- struct{}{}
|
||||
} else {
|
||||
log.Printf("Error reading from connection: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Consumer) OnMessage(ctx context.Context, msg *codec.Message, conn net.Conn) error {
|
||||
@@ -828,6 +834,10 @@ func minInt(a, b int) int {
|
||||
return b
|
||||
}
|
||||
|
||||
func (c *Consumer) isConnectionClosed(err error) bool {
|
||||
return err == io.EOF || strings.Contains(err.Error(), "connection closed") || strings.Contains(err.Error(), "connection reset")
|
||||
}
|
||||
|
||||
func isConnectionError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
|
Reference in New Issue
Block a user