PHPackages                             phpgears/event-async - 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. [Queues &amp; Workers](/categories/queues)
4. /
5. phpgears/event-async

ActiveLibrary[Queues &amp; Workers](/categories/queues)

phpgears/event-async
====================

Async decorator for Event bus

0.2.1(6y ago)01021MITPHPPHP ^7.1CI failing

Since Nov 24Pushed 5y ago1 watchersCompare

[ Source](https://github.com/phpgears/event-async)[ Packagist](https://packagist.org/packages/phpgears/event-async)[ Docs](https://github.com/phpgears/event-async)[ RSS](/packages/phpgears-event-async/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (15)Versions (8)Used By (1)

[![PHP version](https://camo.githubusercontent.com/d0b5687c6812c5d52d86a548e09db527eeb7860f82adbb677de00a36ddbed1b4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d253345253344372e312d3838393242462e7376673f7374796c653d666c61742d737175617265)](http://php.net)[![Latest Version](https://camo.githubusercontent.com/e64ca7781972683c88f0d420034d0618f2c789ca1bdc6e7f3d74a31676a400c6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70687067656172732f6576656e742d6173796e632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpgears/event-async)[![License](https://camo.githubusercontent.com/496008f0f9f7f92c973bd79c9b7d0d6c34692663a0d9d58bfa7ac4a64d88a178/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f70687067656172732f6576656e742d6173796e632e7376673f7374796c653d666c61742d737175617265)](https://github.com/phpgears/event-async/blob/master/LICENSE)

[![Build Status](https://camo.githubusercontent.com/11ee9cb71eb18464dadfc40b56a8ed351e78fc2df4533a6f8934bb70477871fb/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f70687067656172732f6576656e742d6173796e632e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/phpgears/event-async)[![Style Check](https://camo.githubusercontent.com/4c377ef416d656e8cb731fd5124969e748cc9fdd1e2cb2c8a60db45030f7eed9/68747470733a2f2f7374796c6563692e696f2f7265706f732f3135383735353933342f736869656c64)](https://styleci.io/repos/158755934)[![Code Quality](https://camo.githubusercontent.com/6b588621eb341f2759a31156d8bc49141c545f61928fc15e5ed85d2121779c52/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f70687067656172732f6576656e742d6173796e632e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/phpgears/event-async)[![Code Coverage](https://camo.githubusercontent.com/7caf98ccc20b60464115516a583ec4c11ea5fc7316d1f53ee2033aa58cbb58e3/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f70687067656172732f6576656e742d6173796e632e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/github/phpgears/event-async)

[![Total Downloads](https://camo.githubusercontent.com/263fcca381301666aa498c7c07e68dde9c1eb7cc870f30c8810b01455d356b56/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70687067656172732f6576656e742d6173796e632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpgears/event-async/stats)[![Monthly Downloads](https://camo.githubusercontent.com/f68b6b17be9c126633caf30ed612aa831859c330b5a262706729e14a5a0184f4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f70687067656172732f6576656e742d6173796e632e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpgears/event-async/stats)

Async Event
===========

[](#async-event)

Async decorator for Event bus

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

[](#installation)

### Composer

[](#composer)

```
composer require phpgears/event-async

```

Usage
-----

[](#usage)

Require composer autoload file

```
require './vendor/autoload.php';
```

### Asynchronous Events Bus

[](#asynchronous-events-bus)

Event bus decorator to handle events asynchronously

#### Enqueue

[](#enqueue)

```
use Gears\Event\Async\AsyncEventBus;
use Gears\Event\Async\Serializer\JsonEventSerializer;
use Gears\Event\Async\Discriminator\ParameterEventDiscriminator;

/* @var \Gears\Event\EventBus $eventBus */

/* @var Gears\Event\Async\EventQueue $eventQueue */
$eventQueue = new CustomEventQueue(new JsonEventSerializer());

$asyncEventBus new AsyncEventBus(
    $eventBus,
    $eventQueue,
    new ParameterEventDiscriminator('async')
);

$asyncEvent = new CustomEvent(['async' => true]);

$asyncEventBus->dispatch($asyncEvent);
```

Please mind that enqueuing process is independent of event handling, does not prevent the event from being handled. Enqueuing an event happens in first place and then the event is dispatched as normal to the wrapped event bus

#### Dequeue

[](#dequeue)

This part is highly dependent on the message queue of your choosing, though event serializers can be used to deserialize queue message

This is just an example of the process

```
use Gears\Event\Async\ReceivedEvent;
use Gears\Event\Async\Serializer\JsonEventSerializer;

/* @var \Gears\Event\Async\AsyncEventBus $asyncEventBus */
/* @var your_message_queue_manager $queue */

$serializer = new JsonEventSerializer();

while (true) {
  $message = $queue->getMessage();

  if ($message !== null) {
    $event = new ReceivedEvent($serializer->fromSerialized($message));

    $asyncEventBus->dispatch($event);
  }
}
```

Deserialized events should be wrapped in `Gears\Event\Async\ReceivedEvent` in order to avoid infinite loops should you decide to dispatch the events to an async event bus. **If you decide to use a non-async bus on the dequeue side you don't need to do this wrapping**

### Discriminator

[](#discriminator)

Discriminates whether a event should or should not be enqueued based on arbitrary conditions

Three discriminators are provided in this package

- `Gears\Event\Async\Discriminator\ArrayEventDiscriminator` selects events if they are present in the array provided
- `Gears\Event\Async\Discriminator\ClassEventDiscriminator` selects events by their class or interface
- `Gears\Event\Async\Discriminator\ParameterEventDiscriminator` selects events by the presence of a event payload parameter (optionally by its value as well)

### Event queue

[](#event-queue)

This is the one responsible for actual async handling, which would normally be sending the serialized event to a message queue system such as RabbitMQ

No implementation is provided in this package but an abstract base class so you can extend from it

```
use Gears\Event\Async\AbstractEventQueue;

class CustomEventQueue extends AbstractEventQueue
{
  public function send(Event $event): void
  {
    // Do the actual enqueue of $this->getSerializedEvent($event);
  }
}
```

You can use [event-async-queue-interop](https://github.com/phpgears/event-async-queue-interop) that uses [queue-interop](https://github.com/queue-interop/queue-interop) for enqueuing messages

### Serializer

[](#serializer)

Abstract event queue uses serializers to do event serialization so it can be sent to the message queue as a string message

`Gears\Event\Async\Serializer\JsonEventSerializer` is directly provided as a general serializer allowing maximum compatibility in case of events being handled by other systems

You can create your own serializer if the one provided does not fit your needs, for example by using *JMS serializer*, by implementing `Gears\Event\Async\Serializer\EventSerializer` interface

### Distributed systems

[](#distributed-systems)

On distributed systems, such as micro-service systems, events can be dequeued on a completely different part of the system, this part should of course know about events triggered and their contents but could eventually not have access to the event class itself

For example in the context of Domain Events on DDD a bounded context could react to events triggered by another completely different bounded context and of course won't be able to deserialize the original event as it is located on another domain

This can be solved in one of two ways, transform messages coming out from the message queue before handing them to the event serializer, or better by creating a custom `Gears\Event\Async\Serializer\EventSerializer` encapsulating this transformation

*Transformation can be as simple as changing event class to be reconstituted*

Contributing
------------

[](#contributing)

Found a bug or have a feature request? [Please open a new issue](https://github.com/phpgears/event-async/issues). Have a look at existing issues before.

See file [CONTRIBUTING.md](https://github.com/phpgears/event-async/blob/master/CONTRIBUTING.md)

License
-------

[](#license)

See file [LICENSE](https://github.com/phpgears/event-async/blob/master/LICENSE) included with the source code for a copy of the license terms.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Every ~62 days

Recently: every ~56 days

Total

6

Last Release

2414d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4c50421f1ab4148354dc2dd5dcaba168656b17ea913b310d112deb39a6f73ca1?d=identicon)[juliangut](/maintainers/juliangut)

---

Top Contributors

[![juliangut](https://avatars.githubusercontent.com/u/1104131?v=4)](https://github.com/juliangut "juliangut (11 commits)")

---

Tags

eventasyncasynchronousbus

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/phpgears-event-async/health.svg)

```
[![Health](https://phpackages.com/badges/phpgears-event-async/health.svg)](https://phpackages.com/packages/phpgears-event-async)
```

###  Alternatives

[amphp/amp

A non-blocking concurrency framework for PHP applications.

4.4k123.4M323](/packages/amphp-amp)[revolt/event-loop

Rock-solid event loop for concurrent PHP applications.

91943.6M138](/packages/revolt-event-loop)[amphp/parallel

Parallel processing component for Amp.

84746.2M74](/packages/amphp-parallel)[icicleio/icicle

Icicle is a PHP library for writing asynchronous code using synchronous coding techniques.

1.1k150.9k14](/packages/icicleio-icicle)[recoil/recoil

Asynchronous coroutines for PHP 7.

78961.5k7](/packages/recoil-recoil)[amphp/sync

Non-blocking synchronization primitives for PHP based on Amp and Revolt.

18852.8M39](/packages/amphp-sync)

PHPackages © 2026

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