Allow Alternate Message Formats

Created on 23 February 2020, almost 5 years ago
Updated 12 October 2023, about 1 year ago

Summary

The \Drupal\kafka\Queue\KafkaQueue / \Drupal\kafka\Queue\KafkaItem classes have hard-coded handling for serializing / unserializing the messages sent to, and received from Kafka, preventing other formats like JSON from being sent to Kafka.

For example, the producer code looks like this:

  public function createItem($data) {
    if (!$this->isExisting || $this->isDeleted) {
      throw new \RuntimeException(new TranslatableMarkup(
        "Queue @name is not usable at this time.", ['@name' => $this->name]
      ));
    }

    $item = new KafkaItem($data, $this->uuid->generate());
    $this->producerTopic()->produce(RD_KAFKA_PARTITION_UA, 0, $item->payloadString());
    return $item->item_id;
  }


  public function payloadString() {
    // Order the keys for better readability of the serialized format, making
    // it usable without the class if needed.
    $array = [
      'item_id' => $this->item_id,
      'created' => $this->created,
      'data' => $this->data,
    ];

    return serialize($array);
  }

Using PHP's serialize function, without allowing a path for override seriously limits the utility of this module since PHP's serialize function is not a universal standard across other applications that might need to communicate with Drupal.

Expected Results

We should be able to easily override the format of messages produced to Kafka through the Queue interface, without having to override the \Drupal\kafka\Queue\KafkaQueue.

✨ Feature request
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States christophersmith262

Live updates comments and jobs are added and updated live.
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.

Production build 0.71.5 2024