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
795 stars 129 forks source link

consumer Run is blocking code #181

Closed justjack1521 closed 3 months ago

justjack1521 commented 3 months ago

I have upgraded to v0.14.2 and am running into issues with consumer.Run() being blocking code, for example, in the below code "Consumer running" will never print, unless consumer.Run() is wrapped in a goroutine.

consumer, err := rabbitmq.NewConsumer(
    conn,
    "client.update",
    rabbitmq.WithConsumerOptionsRoutingKey("client.disconnected"),
    rabbitmq.WithConsumerOptionsExchangeName("client"),
    rabbitmq.WithConsumerOptionsExchangeDeclare,
    rabbitmq.WithConsumerOptionsExchangeDurable,
)
if err != nil {
    log.Fatal(err)
}
defer consumer.Close()

log.Println("Consumer created")

err = consumer.Run(func(d rabbitmq.Delivery) (action rabbitmq.Action) {
    return rabbitmq.Ack
})
if err != nil {
    log.Fatal(err)
}

log.Println("Consumer running")

Is this intended behaviour?

wagslane commented 3 months ago

This has been expected for awhile iirc, the examples indicate the same