Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need a way to create non-auto recovery RMQConnection #174

Open
tanphamanhh opened this issue Jan 30, 2020 · 4 comments
Open

Need a way to create non-auto recovery RMQConnection #174

tanphamanhh opened this issue Jan 30, 2020 · 4 comments

Comments

@tanphamanhh
Copy link

As title was told. I don't find any way to create a RMQ Connection without auto recovery.
I think it is necessary option when create a connection (like Java Library)

@mattfiocca
Copy link

mattfiocca commented Oct 21, 2022

I have the same requirement; our use case is such that we are using access tokens as passwords that are proxied through an HTTP backend for authentication. Auto-recovery fails for us because the tokens could be expired at the point of retrying the connection.

I have gotten around this though, by attaching a publisher (swift Combine) to our delegate class that can be subscribed to for disconnect events. From there we can manually tear the connection down and rebuild tokens as needed.

Maybe this can help others:

@objc class ConnectionDelegate: NSObject, RMQConnectionDelegate {

    var disconnectCalled = PassthroughSubject<Bool,Never>()

    ...

    func connection(_ connection: RMQConnection!, disconnectedWithError error: Error!) {
        disconnectCalled.send(true)
    }
    
    ...
}

let connection_delegate = ConnectionDelegate()
let disconnect_subscription = connection_delegate!.disconnectCalled.sink { [weak self] _ in
    guard let self_ = self else { return }

    // teardown, refresh tokens, reconnect, etc...
    self_.doTearDownAndReconnect()
}

...

let connection = RMQConnection(
    transport: transport,
    config: config,
    handshakeTimeout: 10,
    channelAllocator: allocator!,
    frameHandler: allocator!,
    delegate: connection_delegate!,
    command: commandQueue!,
    waiterFactory: RMQSemaphoreWaiterFactory(),
    heartbeatSender: heartbeatSender!)

connection?.start()

@michaelklishin
Copy link
Member

Other clients have relevant features such as:

  • Support for connection.update-secret (I may misremember the name) protocol extension introduced together with JWT authentication support
  • Connection lifecycle callbacks

@michaelklishin
Copy link
Member

While disabling recovery would be one reasonable option, both features above can be just as relevant, in particular with modern RabbitMQ versions.

@mattfiocca
Copy link

@michaelklishin, means to inject updated secrets prior to reconnect attempts would be marvelous..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants