Database Table: queue_message and queue_message_status for Cron-Driven Queues

Introduction

Magento 2.4.6 Message Queues enable powerful asynchronous processing for tasks such as order updates, inventory synchronization, bulk attribute updates, and third‑party integrations. These tasks are often initiated or coordinated by Magento cron jobs and message queues, reducing frontend load and improving overall performance.

At the core of this system are two database tables:

  • queue_message
  • queue_message_status

Together, they form a critical part of Magento asynchronous processing and the broader Magento queue system architecture. In this nineteenth post of our Magento 2.4.6 Cron series, we explore how these tables support cron‑driven queues, including sample data, queries, and their interaction with Magento queue consumers via bin/magento queue:consumers:start (Part 14).

Building on Part 18: Database Table: cache_config in Magento 2.4.6 for Cron‑Driven Caching, this post focuses on queue management for asynchronous workloads using Magento RabbitMQ integration. Let’s dive in.

Overview of queue_message and queue_message_status Tables

The queue_message and queue_message_status tables are foundational to Magento 2.4.6 Message Queues. They were introduced to support scalable Magento asynchronous processing, especially for high‑volume operations such as MSI, GraphQL requests, and external system integrations.

These tables work closely with Magento cron jobs and message queues, where cron schedules publish messages and background consumers process them asynchronously.

Roles in Cron‑Driven Queues

  • queue_message
    Stores the actual message payload and metadata such as the topic name.
  • queue_message_status
    Tracks the lifecycle of each message, forming the Queue message status table Magento relies on for monitoring processing states.
  • Cron Integration
    Cron jobs defined in crontab.xml publish messages, while Magento queue consumers process them using queue:consumers:start.
  • Performance Impact
    Enables non‑blocking execution of heavy tasks, reducing cron load and improving throughput when paired with Magento RabbitMQ integration (RabbitMQ 4.x in Magento 2.4.6).

These roles highlight how Magento 2.4.6 Message Queues enhance scalability and reliability.

Detailed Breakdown of Table Structures

Table: queue_message

Stores the message content and its associated topic.

Field Type Null Key Extra Description
id bigint(20) unsigned NO PRI auto_increment Primary key, unique message ID
topic_name varchar(255) NO MUL Message topic (e.g., inventory.source.items.cleanup)
body text YES Message payload (serialized data)

This table represents the message layer of the Magento queue system architecture.

Table: queue_message_status

Tracks the processing state of each message.

Field Type Null Key Default Extra Description
id bigint(20) unsigned NO PRI NULL auto_increment Primary key
message_id bigint(20) unsigned NO MUL NULL Foreign key to queue_message.id
status smallint(5) unsigned NO MUL NULL 1=pending, 2=processing, 3=done, 4=error
updated_at timestamp NO CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP Last update time
retry_count smallint(5) unsigned YES 0 Number of retry attempts

This is the primary Queue message status table Magento uses to track execution progress.

Constraints and Indexes

  • Primary Keys
    id in both tables.
  • Foreign Key
    queue_message_status.message_idqueue_message.id.
  • Indexes
    • QUEUE_MESSAGE_TOPIC_NAME on topic_name for topic‑based filtering
    • QUEUE_MESSAGE_STATUS_MESSAGE_ID for efficient joins
    • QUEUE_MESSAGE_STATUS_STATUS for filtering by state
  • Engine
    InnoDB – ensures transactional integrity for Magento asynchronous processing.
  • Character Set
    utf8mb4_general_ci – supports diverse payloads and integrations.

These optimizations are essential for Magento 2.4.6 Message Queues operating at scale.

Sample Data Entries and Their Significance

Sample Data: queue_message

id topic_name body
100 inventory.source.items.cleanup
101 product_action_attribute.update }

Sample Data: queue_message_status

id message_id status updated_at retry_count
1 100 3 2025-09-09 10:00:10 0
2 101 4 2025-09-09 10:00:15 2

Significance

  • Message 100 (Done)
    Inventory cleanup processed successfully by a Magento queue consumer started via queue:consumers:start.
  • Message 101 (Error)
    Product attribute update failed after retries, highlighting error handling within Magento cron jobs and message queues.

These examples demonstrate how Magento 2.4.6 Message Queues track success and failure states.

Querying the Tables for Insights

Sample Query: Messages by Status

SELECT 
    qm.topic_name, 
    qms.status, 
    COUNT(*) AS count
FROM 
    queue_message qm
JOIN 
    queue_message_status qms 
    ON qm.id = qms.message_id
WHERE 
    qms.updated_at >= '2025-09-01 00:00:00'
GROUP BY 
    qm.topic_name, qms.status
ORDER BY 
    count DESC;

Interpretation:
Inventory cleanup tasks succeed frequently, while attribute updates show errors requiring investigation. This insight is crucial when tuning Magento asynchronous processing.

Sample Query: Failed Messages with Retries

SELECT 
    qm.topic_name, 
    qm.body, 
    qms.retry_count
FROM 
    queue_message qm
JOIN 
    queue_message_status qms 
    ON qm.id = qms.message_id
WHERE 
    qms.status = 4
ORDER BY 
    qms.retry_count DESC;

This query helps identify recurring failures in the Queue message status table Magento depends on for diagnostics.

Sample Code: Cron‑Driven Message Publishing

< ?php

namespace Vendor\Module\Cron;
use Magento\Framework\MessageQueue\PublisherInterface;

class QueueMessage
{
    protected $publisher;

    public function __construct(PublisherInterface $publisher)
    {
        $this->publisher = $publisher;
    }

    public function execute()
    {
        $message = ['sku' => 'ABC123', 'source' => 'default'];
        $this->publisher->publish('inventory.source.items.cleanup', $message);
    }
}

Start the consumer:

php bin/magento queue:consumers:start inventory.source.items.cleanup

This demonstrates real‑world usage of Magento queue consumers with Magento cron jobs and message queues.

Hello Store Owners, ready to take your business online or upgrade your existing store?

Get high-quality Website Development and Optimization Services designed to boost performance, speed, and sales.

Let’s connect with us and build something great together.

Contact Us

Flowchart: Queue and Cron Interaction

Cron Job Publishes
(Message)

Insert queue_message
(topic_name, body)

queue_message_status
(status = pending)

queue:consumers:start
Processes Message

Update Status
(done / error)

exception.log
(if error)

This flow ties together Magento RabbitMQ integration, consumers, and cron execution.

Best Practices for Queue Tables

  • Monitor Statuses
    Regularly check status 4 in the Queue message status table Magento uses for error tracking.
  • Limit Retries
    Configure retry limits in queue.xml to avoid infinite loops.
  • Align with Cron
    Ensure cron schedules align with consumer availability.
  • Use RabbitMQ
    Enable Magento RabbitMQ integration for optimal performance in Magento 2.4.6.
  • Clean Old Messages
    Periodically purge old records to keep Magento 2.4.6 Message Queues efficient.

Engagement Tip

Explore your queue_message_status table and identify the most frequent failing topic_name. How did you resolve the issue within your Magento queue system architecture?

What’s Next?

This post explored queue_message and queue_message_status in Magento 2.4.6 Message Queues

In Part 20: Database Table: core_config_data in Magento 2.4.6 for Cron Settings ↗, we’ll examine how cron configurations are stored and managed. 

Stay tuned!

Latest Posts