rabbitmq-objc-client icon indicating copy to clipboard operation
rabbitmq-objc-client copied to clipboard

Need a way to create non-auto recovery RMQConnection

Open tanphamanhh opened this issue 5 years ago • 4 comments

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)

tanphamanhh avatar Jan 30 '20 09:01 tanphamanhh

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()

mattfiocca avatar Oct 21 '22 15:10 mattfiocca

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 avatar Oct 22 '22 10:10 michaelklishin

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

michaelklishin avatar Oct 22 '22 10:10 michaelklishin

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

mattfiocca avatar Oct 23 '22 00:10 mattfiocca