Search by

silpo-tech / message-bus-bundle

food-tech-devs

Message bus bundle for Symfony

Package info

github.com/silpo-tech/MessageBusBundle

Type:symfony-bundle

pkg:composer/silpo-tech/message-bus-bundle

Statistics

Installs: 5 614

Dependents: 1

Suggesters: 1

Stars: 2

Open Issues: 2

v1.3.0 2026-11-27 15:13 UTC

This package is auto-updated.

Last update: 2026-11-27 15:15:23 UTC


README

CI codecov License: MIT

Development

Run tests

make test # SKIP_INSTALL=true (if you have already installed dependencies)

To list all available commands

make help

Installation

Require the bundle and its dependencies with composer:

$ composer require silpo-tech/message-bus-bundle

Register the bundle:

// project/config/bundles.php

return [
    MessageBusBundle\MessageBusBundle::class => ['all' => true],
];

Add tags to batch processor to tell application where to look for batch processors

    MessageBusBundle\EnqueueProcessor\Batch\BatchProcessorInterface:
      tags:
        - 'enqueue.transport.processor'
        - name: !php/const MessageBusBundle\EnqueueProcessor\Batch\AbstractBatchProcessor::BATCH_PROCESSOR_TAG
          indexed_by: key

Start consuming:

./bin/console enqueue:consume --setup-broker -vvv

How to enable messages compression:

message_bus:
  default_encoder: gzip #available: null, gzip, zlib, deflate

and use MessageBusBundle\Producer\EncoderProducerInterface in your project*. Such service is not available by default.

  • Do not forget to enable zlib extension at PHP.

Heartbeat for long-running handlers

php-amqplib is single-threaded: a heartbeat is sent only when the connection is touched. A handler that works longer than the heartbeat interval (MESSAGE_BUS_HEARTBEAT) without touching the connection loses it.

MessageBusBundle\Service\ConsumerHeartbeat is registered by the bundle and attached to the current consumer automatically (on consume.pre_start, detached on consume.finished and consume.exception). Inject it and call it from long loops:

use MessageBusBundle\Service\ConsumerHeartbeat;

final readonly class ImportStage
{
    public function __construct(private ConsumerHeartbeat $heartbeat)
    {
    }

    public function __invoke(iterable $rows): void
    {
        foreach ($this->heartbeat->wrap($rows) as $row) {
            // slow work
        }

        $this->heartbeat->beat(); // or between slow steps
    }
}

beat() checks the connection at most once per 5 seconds, so it is cheap to call often. It does nothing when no consumer is attached (HTTP requests, CLI commands, tests).