This commit is contained in:
sujit
2025-09-24 18:09:55 +05:45
parent 43f315e07c
commit 428ec634f7
3 changed files with 73 additions and 16 deletions

View File

@@ -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