Support defining message basic properties (for example, for priority queues)

Created on 23 April 2018, over 6 years ago
Updated 7 April 2023, over 1 year ago

Problem/Motivation

Since v. 3.5.0 RabbitMQ supports priority queues. This allows items to be created with a specific priority, and the message broker (the queue) will try to handle its delivery respecting the priority value.

However, the current implementation hardcodes only delivery_mode as property when creating messages:

  public function createItem($data) {
    $logger_args = [
      'channel' => static::LOGGER_CHANNEL,
      '%queue' => $this->name,
    ];

    try {
      $channel = $this->getChannel();
      // Data must be a string.
      $item = new AMQPMessage(json_encode($data), ['delivery_mode' => 2]);

It would be ideal if we could allow the caller to specify other properties of the message being created, which would allow the usage of the priority feature, for example.

Proposed resolution

Define an interface, e.g., QueueItemWithPropertiesInterface, having a method to retrieve the data and one to retrieve the properties to add to the message. In the createItem($data) of the Queue class you could retrieve the properties (and data) when the $data argument is an instance of QueueItemWithPropertiesInterface.

Remaining tasks

  1. Review merge-requests

User interface changes

N.a.

API changes

N.a.

Data model changes

N.a.

✨ Feature request
Status

Fixed

Version

4.0

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain marcoscano Barcelona, Spain

Live updates comments and jobs are added and updated live.
  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • @watergate opened merge request.
  • πŸ‡³πŸ‡±Netherlands watergate

    I've updated the issue description based on the above comments.

    Resolved merge conflicts on the original merge-request, so that it can be merged to the 3.x branch, and made some improvements (such as adhering to coding standards, ensuring the test proceeds, changing the name of the interface and adding a default implementation).

    Added an extra merge-request for the 4.x branch, containing the same changes as for the 3.x branch.

    • cmlara β†’ committed d7354177 on 3.x
      Issue #2964644 by Watergate, cmlara, marcoscano, zach.bimson, joachim:...
  • Status changed to Fixed over 1 year ago
  • πŸ‡ΊπŸ‡ΈUnited States cmlara

    Thank you for the updates to the 3.x branch and for creating the 4.x branch as well, I've merged both.

    Probably a wise move that we have an have an actual implementation in the code so that is a good addition.

    Also nice update on the message count portion of the test as well to avoid possible issues.

    Marking as fixed.

    I will write up a change record for this and publish it, adding the tag to make sure I come back and do so.

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024