Listening to the connection with rabbit, it turned out that heartbeats are sent only from the server to the devices, but they aren't sent from the device to the server (Android devices send heartbeats). Because of what, after about 3 minutes, the connection is broken with the message "Socket closed by remote peer". What could be the problem?
Having figured out what will happen if you use the standard connection as in the documentation, it turns off after 3 minutes, since the default heartbeatSender is weak and becomes nil. After that, the server does not receive messages from the client and closes the connection.
I have to create my own connection where RMQGCDHeartbeatSender will stay alive.
let tlsOptions = RMQTLSOptions.fromURI(connectionUri)
let rmqURI = try! RMQURI.parse(connectionUri)
let transport = RMQTCPSocketTransport(host: rmqURI.host, port: rmqURI.portNumber, tlsOptions: tlsOptions, connectTimeout: RMQDefaultConnectTimeout, readTimeout: RMQDefaultReadTimeout, writeTimeout: RMQDefaultWriteTimeout)
let allocator = RMQMultipleChannelAllocator(maxCapacity: UInt16(RMQChannelMaxDefault), channelSyncTimeout: RMQDefaultSyncTimeout)!
let waiterFactory = RMQSemaphoreWaiterFactory()
let nameGenerator = RMQProcessInfoNameGenerator()
let command = RMQGCDSerialQueue(name: nameGenerator.generate(withPrefix: "connection-commands"))!
let heartbeatSender = RMQGCDHeartbeatSender(transport: transport, clock: RMQTickingClock())!
self.heartbeatSender = heartbeatSender /* strong link */
let delegateProxy = RMQQueuingConnectionDelegateProxy(delegate: logger, queue: RMQConnection.defaultDispatchQueue())
let recovery = RMQConnectionRecover(interval: RMQDefaultRecoveryInterval, attemptLimit: NSNumber(value: Int.max), onlyErrors: false, heartbeatSender: heartbeatSender, command: command, delegate: delegateProxy)!
let credentials = RMQCredentials(username: rmqURI.username, password: rmqURI.password)
let config = RMQConnectionConfig(credentials: credentials, channelMax: NSNumber(value: RMQChannelMaxDefault), frameMax: NSNumber(value: RMQFrameMax), heartbeat: RMQDefaultHeartbeatTimeout, vhost: rmqURI.vhost, authMechanism: tlsOptions.authMechanism(), userProvidedConnectionName: "", recovery: recovery)
connection = RMQConnection(transport: transport, config: config, handshakeTimeout: NSNumber(value: 60), channelAllocator: allocator, frameHandler: allocator, delegate: logger, command: command, waiterFactory: waiterFactory, heartbeatSender: heartbeatSender)