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

Make channelManager public #89

Closed gnuletik closed 1 year ago

gnuletik commented 2 years ago

Hi !

Thanks for this useful lib! I'm wondering if the channelManager struct could be exposed (renamed to ChannelManager) to be imported. It could also be useful to expose the channelManager struct values of Consumer / Publisher.

My use case is that I'd like to do manual creation of exchange and queues. I can create a new new AMQP channel but I'd lose the auto reconnect handling of the channelManager.

Thanks!

shoham-b commented 2 years ago

I understand why exposing the channelManager is undesirable, as it might make others depend on a specific private implementation which might change in the future. It might be better to add a connection that supports exposing the actual amqp library for exceptional cases such as only declaring an exchange or something like it. This way it is possible to manage access to them in a unified manner.

wagslane commented 1 year ago

Check out the updated API on the main branch. The Conn is new a separate public struct

gnuletik commented 1 year ago

Thanks for the change @wagslane !

However, the public Conn struct does not let me access the underlying amqp.Channel (which is now stored in github.com/wagslane/go-rabbitmq/internal/connectionmanager.ConnectionManager.channel).

My usecase for this issue is to let me call QueueDeclare, ExchangeDeclare and QueueBind. These calls are available in ConnectionManager.QueueBindSafe() and related funcs.

What would work for my usecase would be to:

For the reference, here is the related commit: https://github.com/wagslane/go-rabbitmq/commit/0df88ac7e9af0ee5cd217e1c3a04729b02b8322c

gnuletik commented 1 year ago

@wagslane Should I create a new issue for this? Thanks !

wagslane commented 1 year ago

Sorry, I think this is something you should just use AMQP for @gnuletik

gnuletik commented 1 year ago

I did a copy of ConnectionManager and ChannelManager in my repo and that works well. This does exactly what I need. So, I think that could be quite useful to export these symbols to import these instead of copying.

GuihaiHU commented 1 year ago

I did a copy of ConnectionManager and ChannelManager in my repo and that works well. This does exactly what I need. So, I think that could be quite useful to export these symbols to import these instead of copying.

I Need to visit QueueDeclare too. Becase this package cannot declare queue if I want to use default exchange.