wagslane / go-rabbitmq

A wrapper of streadway/amqp that provides reconnection logic and sane defaults
https://blog.boot.dev/golang/connecting-to-rabbitmq-in-golang-easy/
MIT License
752 stars 126 forks source link

Shutdown after a fixed number of reconnection attempts #139

Closed abbasegbeyemi closed 9 months ago

abbasegbeyemi commented 11 months ago

I want to be able to shut down the consumer/publisher gouroutines and by extension the entire app after a few attempts at reconnecting to the rabbitmq server. Is there a way to implement this with this library?

I can see that the ChannelManager and ConnectionManager both increment reconnection count, is there a way to use this value to determine when the managers should give up trying to reconnect?

wagslane commented 9 months ago

If you want that kind of granular control I think the base amqp lib is for you

ValikoDorodnov commented 4 months ago

@wagslane Thank you for you library, it`s very useful for RabbitMQ tasks. But this functional is still important for control all connection lifecycle. You already have reconnectionCount var

// ChannelManager -
type ChannelManager struct {
    logger               logger.Logger
    channel              *amqp.Channel
    connManager          *connectionmanager.ConnectionManager
    channelMux           *sync.RWMutex
    reconnectInterval    time.Duration
    reconnectionCount    uint --> this var
    reconnectionCountMux *sync.Mutex
    dispatcher           *dispatcher.Dispatcher
}

I wonder you can add a stop function for number of attempts, thank you!