rabbitmq-objc-client
rabbitmq-objc-client copied to clipboard
Need a way to create non-auto recovery RMQConnection
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)
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()
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
While disabling recovery would be one reasonable option, both features above can be just as relevant, in particular with modern RabbitMQ versions.
@michaelklishin, means to inject updated secrets prior to reconnect attempts would be marvelous..