Print stats on nsq consumer

This commit is contained in:
2026-01-26 12:30:45 +01:00
parent 43a49c4dbd
commit 201f24a429

View File

@@ -27,7 +27,18 @@ func ConnectToNSQ(topic, channel string, handler nsq.Handler) (*nsq.Consumer, er
return nil, fmt.Errorf("failed to connect to NSQD: %w", err)
}
return consumer, nil
timeout := 10 * time.Second
deadline := time.Now().Add(timeout)
for time.Now().Before(deadline) {
stats := consumer.Stats()
if stats.Connections > 0 {
return consumer, nil
}
time.Sleep(100 * time.Millisecond)
}
consumer.Stop()
return nil, fmt.Errorf("timeout waiting for NSQ connection after %v", timeout)
}
func NewProducer() (*nsq.Producer, error) {