Print stats on nsq consumer
This commit is contained in:
13
lnsq/nsq.go
13
lnsq/nsq.go
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user