PHPackages                             werkspot/message-bus - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. werkspot/message-bus

AbandonedArchivedLibrary[Utility &amp; Helpers](/categories/utility)

werkspot/message-bus
====================

A generic message bus that can be used to implement a CommandBus or an EventBus or any other similar construction.

223PHP

Since Oct 11Pushed 8y ago3 watchersCompare

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

READMEChangelogDependenciesVersions (1)Used By (0)

Werkspot \\ MessageBus
======================

[](#werkspot--messagebus)

[![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/3fb82a6106e4e1daf5c058de14dfa295c0e3969bfb8d8b1d2cde5abf7327ade9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f7765726b73706f742f6d6573736167652d6275732e7376673f7374796c653d666c61742d737175617265)](https://github.com/werkspot/message-bus/releases)[![Total Downloads](https://camo.githubusercontent.com/69298ebdb95c8fb31579348cece18e932602026cab4254a8dfde6c65e1c87846/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7765726b73706f742f6d6573736167652d6275732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/werkspot/message-bus)

[![Build Status](https://camo.githubusercontent.com/1ec406c4e24fffcdbb77f72dbb099d542f1963c71e145778d512374bd659c30c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f6275696c642f672f7765726b73706f742f6d6573736167652d6275732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/werkspot/message-bus/build)[![Coverage Status](https://camo.githubusercontent.com/44f20e64b45782a1bd147cb728c3d2ec0985fd5b8340ecd2aeeb99b251a6f665/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f7765726b73706f742f6d6573736167652d6275732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/werkspot/message-bus/code-structure)[![Quality Score](https://camo.githubusercontent.com/586e65df6fc22275ff547298822b5f90e9dec4b349fc0393ea2139825faca690/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f7765726b73706f742f6d6573736167652d6275732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/werkspot/message-bus)

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

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

A library capable of delivering a message to a destination synchronously or asynchronously, using some other queueing library.

The message to be delivered can be anything and the destination can be specified by any string.

A chain of middlewares can be configured (DeliveryChain), and the message will go through all those middlewares allowing us to do various things, like validating the message, start and commit a transaction, replace the destination according to some criteria, perform some logging, or whatever we need to to before and/or after delivering the message.

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

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

A Message Bus can make a project very flexible and performant. We can easily create a Command Bus, Event Bus, Event Sourcing, Queueing, or any similar construction on top of this Message Bus.

Usage
-----

[](#usage)

The `MessageDispatcher` is the entry point to the message bus. There are already a few middlewares provided with this library, which you can find in `src/Bus/DeliveryChain`.

```
    $bus = Bus::fromMiddlewareList($middleware1, $middleware2 /*,  ... */);

    $messageDispatcher = new MessageDispatcher($bus);

    $messageDispatcher->dispatchSynchronousMessage(
        $someObjectOrStringOrWhatever,      // some payload to deliver, persisted by the MessageRepository
        '{"deliver_to": "SomeServiceId"}',  // destination to be decoded by the delivery service (MessageDeliveryServiceInterface)
        []                                  // some whatever metadata
    );
```

If you need to deliver messages asynchronously, then you need to add the `AsynchronousDeliveryMiddleware` to the bus.

The `AsynchronousDeliveryMiddleware` depends on the `MessageQueueServiceInterface`. So you need to choose a queueing library and create an adapter of that library that implements the `MessageQueueServiceInterface`, so it can be injected in the `AsynchronousDeliveryMiddleware`.

For example:

```
    $messageQueueService = new MessageQueueServiceAdapterThatImplementsMessageQueueServiceInterface(/* ... */);

    $bus = Bus::fromMiddlewareList(
        $middleware1,
        $middleware2,
        new AsynchronousDeliveryMiddleware($messageQueueService)
        /*,  ... */
    );

    // Now you can send an Asynchronous (potentially Queued) message
    $messageDispatcher->dispatchQueuedMessage(
        $someObjectOrStringOrWhatever,       // some payload to deliver, persisted by the MessageRepository
        '{"deliver_to": "SomeServiceId"}',   // destination to be decoded by the delivery service (MessageDeliveryServiceInterface)
        [],                                  // some whatever metadata
        new DateTimeImmutable('2037-10-08'), // some (optional, future) delivery date
        new Priority(Priority::NORMAL)       // some priority, from 1 to 9
    );
```

One thing to be aware of in case you want to dispatch both Synchronous and Asynchronous messages is that you need to make sure the `AsynchronousDeliveryMiddleware` in the bus is called *before* the `SynchronousDeliveryMiddleware`. Otherwise the Synchronous middleware will always handle it before it can be queued, and queueing will not work.

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

[](#installation)

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

```
composer require werkspot/message-bus

```

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

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 61.3% 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 (19 commits)")[![MarijnKoesen](https://avatars.githubusercontent.com/u/711208?v=4)](https://github.com/MarijnKoesen "MarijnKoesen (11 commits)")[![ruudvanderweijde](https://avatars.githubusercontent.com/u/3205112?v=4)](https://github.com/ruudvanderweijde "ruudvanderweijde (1 commits)")

### Embed Badge

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

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

###  Alternatives

[bootflat/bootflat

An open source Flat UI KIT based on Bootstrap (3.3.0). A faster, easier and less repetitive way for web developers to create elegant web apps.

4.2k3.3k](/packages/bootflat-bootflat)[francescomalatesta/laravel-circuit-breaker

A circuit breaker pattern implementation for the Laravel framework

2919.2k2](/packages/francescomalatesta-laravel-circuit-breaker)[techworker/ssml

A PHP library to generate SSML.

1110.1k1](/packages/techworker-ssml)[ziplr/php-qr-code

PHP Qr Code Generator compatible with php 7.0

119.7k](/packages/ziplr-php-qr-code)[fogs/tagging-bundle

Tag any entity in your Symfony2 project.

113.5k](/packages/fogs-tagging-bundle)

PHPackages © 2026

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