PHPackages                             werkspot/message-queue - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. werkspot/message-queue

AbandonedArchivedLibrary

werkspot/message-queue
======================

A generic message queue.

328[1 issues](https://github.com/Werkspot/message-queue/issues)[1 PRs](https://github.com/Werkspot/message-queue/pulls)PHP

Since Sep 19Pushed 8y ago3 watchersCompare

[ Source](https://github.com/Werkspot/message-queue)[ Packagist](https://packagist.org/packages/werkspot/message-queue)[ RSS](/packages/werkspot-message-queue/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (2)Used By (0)

Werkspot \\ MessageQueue
========================

[](#werkspot--messagequeue)

[![Author](https://camo.githubusercontent.com/ec56dda7b3b4228f9a281cbbdddd6e807a495d3c1a1f33e0be015a6775bdbb64/687474703a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d5765726b73706f742d626c75652e7376673f7374796c653d666c61742d737175617265)](https://www.werkspot.com)[![Software License](https://camo.githubusercontent.com/942e017bf0672002dd32a857c95d66f28c5900ab541838c6c664442516309c8a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Latest Version](https://camo.githubusercontent.com/d84d05deb15986f8c2590596d023f685cbac3bc2c1c6a14c7ec4f26bdadd9fd4/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7765726b73706f742f6d6573736167652d71756575652e7376673f7374796c653d666c61742d737175617265)](https://github.com/werkspot/message-queue/releases)[![Total Downloads](https://camo.githubusercontent.com/c81849f8dc2ebb5a3d05f12ba98187e8ae7345909e00f85b3863d9091fcd8a97/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7765726b73706f742f6d6573736167652d71756575652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/werkspot/message-queue)

[![Build Status](https://camo.githubusercontent.com/c1f81e23828a5109abc2dfdc5e7549040d282ee2f3a6b2712842cec277a659cb/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f7765726b73706f742f6d6573736167652d71756575652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/werkspot/message-queue/build)[![Coverage Status](https://camo.githubusercontent.com/a7bc186c2119ac832660808b3dd531d2973abe4abc6f0325c2ce55990bdcf744/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f7765726b73706f742f6d6573736167652d71756575652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/werkspot/message-queue/code-structure)[![Quality Score](https://camo.githubusercontent.com/1d7054103c1ef1917e897971d85f4e238195231069c6a0ffb5496d7aed7644d0/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7765726b73706f742f6d6573736167652d71756575652e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/werkspot/message-queue)

What this project is
--------------------

[](#what-this-project-is)

A library capable of delivering a message to a destination asynchronously, as soon as possible or at a specified date and time.

The message to be delivered can be anything but its serialization must be taken care of by a MessageRepositoryInterface, who's implementation must be provided by the code using this library.

The destination can be specified by any string, but the interpretation of that string, and the effective delivery of the message to the destination must be taken care by the MessageDeliveryServiceInterface, who's implementation must be provided by the code using this library.

This MessageQueue uses two internal queues, one for messages that are scheduled for delivery (the ScheduledQueue, using some persistence mechanism like MySQL) and another queue for messages that are in line for delivery (the DeliveryQueue, using rabbitMq).

Why this project exists
-----------------------

[](#why-this-project-exists)

A message queue is useful to run asynchronous tasks, as soon as possible or at a specified date and time, thus balancing the load on the servers across the time, and allowing for faster responses to users as they will not need to wait for tasks to be done inline which can be done async, like for example sending out emails.

On top of this library we can build a Message Bus, which can decide if a message should be delivered in sync or async. In turn, on top of that Message Bus we can build a Command Bus, which delivers one message to only one destination, or an Event Bus, which can deliver one message to several destinations.

Usage
-----

[](#usage)

The `MessageQueueService` is the entry point to the message queue.

```
    $messageQueueService = new MessageQueueService(
        new ScheduledQueueService(
            new MessageRepository(/*...*/) // implemented by the code using this library
        )
    );

    $messageQueueService->enqueueMessage(
        $someObjectOrStringOrWhatever,      // some payload to deliver, persisted by the MessageRepository
        '{"deliver_to": "SomeServiceId"}',  // destination to be decoded by the delivery service (MessageDeliveryServiceInterface)
        new DateTimeImmutable(),            // delivery date and time
        5,                                  // priority
        []                                  // some whatever metadata
    );
```

in order to move messages from the *ScheduledQueue* to the *DeliveryQueue* we need **one**ScheduledQueueToDeliveryQueueWorker to be running in the background. And to move messages from the DeliveryQueue to the actual destination we need **at least one** DeliveryQueueToHandlerWorker to be running in the background.

Our `$scheduledQueueWorker` will be run, for example, by a CLI command which will be kept alive by a process management tool like Supervisor.

```
    $scheduledQueueWorker = new ScheduledQueueToDeliveryQueueWorker(
        new ScheduledQueueService(new MessageRepository(/*...*/)),
        new AmqpProducer(new AMQPLazyConnection(/*...*/), new UuidMessageIdGenerator()),
        'some_queue_name',
        new SomeLogger(/*...*/)
    );

    $scheduledQueueWorker->moveMessageBatch(50);
```

Like the `$scheduledQueueWorker`, the `$deliveryQueueWorker` is also started by a CLI command and kept alive by a process management tool like Supervisor.

```
    $logger = new SomeLogger(/*...*/);

    $deliveryQueueWorker = new DeliveryQueueToHandlerWorker(
        new AmqpConsumer(
            new AMQPLazyConnection(/*...*/),
            new AmqpMessageHandler(
                new MessageHandler(/*...*/),
                new SomeCache(/*...*/),
                new PersistenceClient(/*...*/),
                $logger
            ),
            $logger
        ),
        'some_queue_name'
    );

    $deliveryQueueWorker->startConsuming(300);
```

Installation
------------

[](#installation)

To install the library, run the command below and you will get the latest version:

```
composer require werkspot/message-queue

```

Tests
-----

[](#tests)

To execute the tests run:

```
make test
```

Coverage
--------

[](#coverage)

To generate the test coverage run:

```
make test_with_coverage
```

Code standards
--------------

[](#code-standards)

To fix the code standards run:

```
make cs-fix
```

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 87.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/99d3da37dfb742ac4a51091f756f8a632cc9d4a12f433fe3c6a51056808372f6?d=identicon)[werkspot](/maintainers/werkspot)

---

Top Contributors

[![hgraca](https://avatars.githubusercontent.com/u/1809002?v=4)](https://github.com/hgraca "hgraca (42 commits)")[![MarijnKoesen](https://avatars.githubusercontent.com/u/711208?v=4)](https://github.com/MarijnKoesen "MarijnKoesen (5 commits)")[![ruudvanderweijde](https://avatars.githubusercontent.com/u/3205112?v=4)](https://github.com/ruudvanderweijde "ruudvanderweijde (1 commits)")

### Embed Badge

![Health badge](/badges/werkspot-message-queue/health.svg)

```
[![Health](https://phpackages.com/badges/werkspot-message-queue/health.svg)](https://phpackages.com/packages/werkspot-message-queue)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
