Tobus
Tobus

Reputation: 95

Apache Artemis doesn't stop scanning for expires

I'm using Apache Artemis ActiveMQ 2.6.3 as an MQTT broker embedded in a Spring 5 application:

@Bean(initMethod = "start", destroyMethod = "stop")
fun embeddedActiveMQ(securityManager: ActiveMQJAASSecurityManager) =
        EmbeddedActiveMQ().apply {
            setConfiguration(getEmbeddedActiveMQConfiguration())
            setConfigResourcePath("activemq-broker.xml")
            setSecurityManager(securityManager)
        }

private fun getEmbeddedActiveMQConfiguration() =
        ConfigurationImpl().apply {
            addAcceptorConfiguration("netty", DefaultConnectionProperties.DEFAULT_BROKER_URL)
            addAcceptorConfiguration("mqtt", "tcp://$host:$mqttPort?protocols=MQTT")

            name = brokerName
            bindingsDirectory = "$dataDir${File.separator}bindings"
            journalDirectory = "$dataDir${File.separator}journal"
            pagingDirectory = "$dataDir${File.separator}paging"
            largeMessagesDirectory = "$dataDir${File.separator}largemessages"
            isPersistenceEnabled = persistence
            connectionTTLOverride = 60000
        }

Although I'm setting the connection TTL to 60 seconds in the above Kotlin code as suggested in the documentation and the client disconnected and terminated an hour ago, the log shows the following entries:

2020-06-22 10:57:03,890 [Thread-29 (ActiveMQ-server-org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl$5@ade4717)] DEBUG o.a.a.a.core.server.impl.QueueImpl - Scanning for expires on client1.some-topic

2020-06-22 10:58:03,889 [Thread-35 (ActiveMQ-server-org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl$5@ade4717)] DEBUG o.a.a.a.core.server.impl.QueueImpl - Scanning for expires on client1.some-topic

Based on these log entries, I'm afraid that "dead" connection resources are never cleaned up by the server.

What should I do to actually remove the "dead" connections from the server to avoid leaking resources?

Upvotes: 0

Views: 298

Answers (1)

Justin Bertram
Justin Bertram

Reputation: 35122

The broker will often create resources like addresses, queues, etc. to deal with clients. In the case of MQTT clients the broker will create queues which essentially represent the client's subscriptions.

In this particular case a queue named client1.some-topic has been created for an MQTT subscription and the broker is scanning that queue for expired messages. At this point it looks like the broker is working as designed.

When a client disconnects without unsubscribing what the broker does with the subscription depends on whether the client used a clean session or not.

If the client used a clean session then the broker will delete the subscription queue when the client disconnects (even in the event of a failure).

Otherwise the broker is obliged to hold on to the subscription queue and route messages to it. If the client never reconnects to unsubscribe then the subscription may fill up with lots of messages and trigger the broker's paging mode and eventually even limit message production altogether. In this case the client can either reconnect and unsubscribe or the subscription queue can be removed administratively.

Upvotes: 1

Related Questions