different type of check connection

This commit is contained in:
nquidox 2026-04-02 15:50:55 +03:00
parent d62d41b41a
commit ecda63761c

View file

@ -4,7 +4,6 @@ import (
"fmt"
amqp "github.com/rabbitmq/amqp091-go"
"log"
"net"
"os"
"sync"
"time"
@ -82,14 +81,26 @@ func NewConsumer(client *Client) Consumer {
}
func (c *Client) connectAndSignal(addr string, timeout time.Duration) error {
dialer := &net.Dialer{Timeout: timeout}
conn, err := amqp.DialConfig(addr, amqp.Config{
Dial: dialer.Dial,
})
if err != nil {
return err
type result struct {
conn *amqp.Connection
err error
}
c.connection = conn
resCh := make(chan result, 1)
go func() {
conn, err := amqp.Dial(addr)
resCh <- result{conn, err}
}()
select {
case <-time.After(timeout):
return fmt.Errorf("connection timeout after %v", timeout)
case res := <-resCh:
if res.err != nil {
return res.err
}
c.connection = res.conn
close(c.connected)
return nil
}
}