Clearing Queued Messages in HiveMQ Cloud

Clearing Queued Messages in HiveMQ Cloud

Overview

This knowledge base article addresses the issue of excessive queued messages accumulating in HiveMQ Cloud and provides steps to identify, resolve, and prevent recurrence of this issue.

Issue Description

A large number of messages (20 million+) accumulated in the message queue due to a client-side bug where clients were publishing with an incorrect protocol. This resulted in messages being queued for offline or slow-consuming clients.

Root Cause

The root cause was identified as a client-side bug that caused improper protocol usage during message publishing. This led to messages accumulating in client queues rather than being properly consumed.

Understanding Message Queuing in HiveMQ

Message queueing occurs in two primary scenarios(1)(https://docs.hivemq.com/hivemq/latest/control-center/information.html):

  • Messages published on topics for which an offline client with an existing session has a subscription

  • An online client cannot consume messages at the same speed as the broker sends them

The current and maximum number of messages in the message queue can be viewed in the Control Center(1)(https://docs.hivemq.com/hivemq/latest/control-center/information.html):

  • Current: Shows the number of messages in the message queue of the client at the time that the snapshot is taken

  • Maximum: Shows the queue size limit that is set for the client

Identifying Queued Messages

Using HiveMQ Control Center

  1. Navigate to Clients in the Control Center(1)(https://docs.hivemq.com/hivemq/latest/control-center/information.html)

  2. Select Refresh Snapshot to create a fresh snapshot of all MQTT sessions(1)(https://docs.hivemq.com/hivemq/latest/control-center/information.html)

  3. Review the Queue Size column which shows current and maximum queue sizes(1)(https://docs.hivemq.com/hivemq/latest/control-center/information.html)

  4. Sort by queue size to identify clients with high message counts(1)(https://docs.hivemq.com/hivemq/latest/control-center/information.html)

  5. Select a client identifier to view detailed client information(1)(https://docs.hivemq.com/hivemq/latest/control-center/information.html)

The Clients overview displays the following information(1)(https://docs.hivemq.com/hivemq/latest/control-center/information.html):

  • Client ID: The unique identifier of the client

  • Connected: Shows whether a client is currently connected

  • Queue Size: Current and maximum number of messages in the message queue

  • Username: The username of the client

  • IP Address: The IP address of the client

Resolution Options

Option 1: Client Reconnection with Clean Session

Have affected clients reconnect with clean_start=1. When a client connects with a non-persistent session, the broker does not save any subscription information when the client disconnects(1)(https://docs.hivemq.com/hivemq/latest/control-center/information.html).

Steps:

  1. Configure clients to reconnect with clean_start=1

  2. The broker will clear the session and all associated queued messages

  3. If message persistence is required, clients can reconnect with clean_start=0 after queue clearance

Option 2: Manual Client Session Invalidation

For HiveMQ Cloud Enterprise deployments with large numbers of affected clients, HiveMQ Support can assist with session invalidation using API-based scripts.

Process:

  1. Identify all clients with excessive queue sizes (e.g., 10,000+ messages)

  2. Create an API token for script execution

  3. Execute invalidation scripts while monitoring cluster resource metrics

  4. Verify queue clearance in Control Center

  5. Delete API token after completion

Option 3: Individual Client Disconnect and Reconnect

For smaller numbers of affected clients:

  1. Locate the client with a high message queue in Control Center → Clients → Queue Size(1)(https://docs.hivemq.com/hivemq/latest/control-center/information.html)

  2. Click on the client to view details(1)(https://docs.hivemq.com/hivemq/latest/control-center/information.html)

  3. Disconnect the client (ensure the client is programmed to reconnect automatically)

  4. Monitor the same client in Control Center → Clients → Queue Size(1)(https://docs.hivemq.com/hivemq/latest/control-center/information.html)

  5. Verify that reconnection clears the message queue and that the metric is not increasing

Monitoring and Verification

Control Center Metrics

Monitor the following metrics in the Control Center(2)(https://docs.hivemq.com/hivemq/latest/control-center/analytic.html):

Dropped Messages Analysis

Review the Dropped Messages view to identify any message delivery issues(2)(https://docs.hivemq.com/hivemq/latest/control-center/analytic.html):

Prevention Strategies

Client-Side Measures

  • Ensure clients use the correct MQTT protocol version

  • Implement proper error handling and reconnection logic

  • Configure clients to consume messages at an appropriate rate

  • Use clean_start=1 when persistent sessions are not required

Broker-Side Configuration

Configure appropriate queue limits in the HiveMQ configuration(3)(https://docs.hivemq.com/hivemq/latest/user-guide/configuration.html):

<hivemq> <mqtt> <queued-messages> <max-queue-size>1000</max-queue-size> <strategy>discard-oldest</strategy> </queued-messages> </mqtt> </hivemq>

Monitoring and Alerting

Additional Resources

Support Escalation

For large-scale queue cleanup operations affecting thousands of clients, contact HiveMQ Support for assistance with:

  • API-based session invalidation scripts

  • Cluster resource monitoring during cleanup

  • Custom cleanup strategies for specific deployment scenarios

Note: This article is based on a production incident where 20 million queued messages were successfully cleared through coordinated session invalidation of 760+ affected clients.