PHPackages                             lukasz93p/async-message-channel - 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. lukasz93p/async-message-channel

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

lukasz93p/async-message-channel
===============================

Package which allow to add and then process asynchronous messages. Currently based on RabbitMQ.

1.1(6y ago)073[1 PRs](https://github.com/Lukasz93P/async-message-channel/pulls)2MITPHPCI passing

Since Nov 17Pushed 3w agoCompare

[ Source](https://github.com/Lukasz93P/async-message-channel)[ Packagist](https://packagist.org/packages/lukasz93p/async-message-channel)[ RSS](/packages/lukasz93p-async-message-channel/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (3)Versions (5)Used By (2)

async-message-channel
=====================

[](#async-message-channel)

##### Current implementation uses RabbitMQ, so to utilize it You have to install this broker.

[](#current-implementation-uses-rabbitmq-so-to-utilize-it-you-have-to-install-this-broker)

Why to use this package?
------------------------

[](#why-to-use-this-package)

- It abstracts all difficulties associated with asynchronous messages publishing and processing.
- It guarantees reliable publication of messages - in case of failure in publication even one of the messages exception is thrown.
- It helps with passing unsuccessfully processed messages back to queue.

How to use
----------

[](#how-to-use)

### Publishing

[](#publishing)

#### 1 Add env configuration:

[](#1-add-env-configuration)

```
MQ_BROKER_HOST={rabbit host}
MQ_BROKER_PORT={rabbit port}
MQ_BROKER_USER={rabbit user}
MQ_BROKER_PASSWORD={rabbit password}

```

#### 2 Create instance of `AsynchronousMessageChannel`:

[](#2-create-instance-of-asynchronousmessagechannel)

```
$asynchronousMessageChannel = AsynchronousMessageChannelFactory::withLogger($implementationOfPsrLoggerInterface);
```

Logger is instance of class implementing `Psr\Log\LoggerInterface`, it will be used to log error which can occur during message processing.

#### 3 Publish message:

[](#3-publish-message)

Message have to be instance of class implementing `PublishableMessage`. Currently implementation is aligned with RabbitMQ requirements so `PublishableMessage` defines three methods:

- `body` - returns body of a message as string
- `routingKey` - returns routing key which will be used by RabbitMQ to route message into proper queues
- `exchangeName` - returns RabbitMQ's exchange name to use for message publishing

You can use default implementation:

```
$asynchronousMessageChannel = AsynchronousMessageChannelFactory::withLogger($implementationOfPsrLoggerInterface);
$publishableMessage = BasicMessage::publishable($routingKeyForMessage, $exchangeNameForMessage, $messageBody);
$asynchronousMessageChannel->add([$publishableMessage]);
```

`AsynchronousMessageChannel::add` receives array of `PublishableMessage`s and publish them reliably in batch manner. If it receives information about publishing failure from RabbitMQ `MessagePublishingFailed` is thrown.

### Processing

[](#processing)

#### 1 Create `MessageHandler`:

[](#1-create-messagehandler)

For messages processing implementation of `MessageHandler` is needed, this interface defines only one method:

```
interface MessageHandler
{
    /**
     * @param ProcessableMessage $message
     * @throws Throwable
     * @throws MessageConstantlyUnprocessable
     * @throws MessageTemporaryUnprocessable
     */
    public function handle(ProcessableMessage $message): void;
}
```

As You can see `handle` receives `ProcessableMessage` as an only argument.

```
interface ProcessableMessage
{
    public function body(): string;
}
```

#### 2 Decide what to do with processed messages inside `MessageHandler::handle`:

[](#2-decide-what-to-do-with-processed-messages-inside-messagehandlerhandle)

Client code can decide what to do with processed message thorough implementation of `handle` method :

- if `handle` method method throws any exception/throwable(excluding `MessageConstantlyUnprocessable`) `AsynchronousMessageChannel` will `reject` message from RabbitMQ. When message is rejected it will be deleted from queue but You can configure RabbitMQ to use `fallback queue` for that purposes and instruct broker to pass messages back from `fallback queue` to any other queue(probably the one to which message was originally added) with some delay.
- if `handle` throws `MessageConstantlyUnprocessable` then `AsynchronousMessageChannel` informs RabbitMQ that message was processed successfully then RabbitMQ simply deletes the message.

##### Summary:

[](#summary)

- All exception thrown by `MessageHandler::handle` will be logged.
- If message has been processed successfully `MessageHandler::handle` should not throw any exception.
- If message processing failed but You **don't want** to receive that message again and log exception then throw `MessageConstantlyUnprocessable` inside `MessageHandler::handle`.
- If message processing failed but You **want** to receive that message again and log exception throw any exception inside `MessageHandler::handle`(You can be more explicit and throw `MessageTemporaryUnprocessable`). To receive message again You also have to configure `fallback queue` for RabbitMQ.

#### 3 Start processing messages:

[](#3-start-processing-messages)

To start processing messages You need and instance of `AsynchronousMessageChannel`:

```
$asynchronousMessageChannel = AsynchronousMessageChannelFactory::withLogger($implementationOfPsrLoggerInterface);
```

And then You should use `AsynchronousMessageChannel::startProcessingQueue`:

```
$asynchronousMessageChannel->startProcessingQueue($myImplementationOfMessageHandler, $nameOfRabbitMQQueueFromWhichMessagesWillBeProcessed);
```

###  Health Score

37

—

LowBetter than 83% of packages

Maintenance62

Regular maintenance activity

Popularity8

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~27 days

Total

2

Last Release

2339d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e1a446071d08efd8bbc3de614e529d7157a8828bc37e61a41a681af34654137?d=identicon)[Lukasz93P](/maintainers/Lukasz93P)

---

Top Contributors

[![Lukasz93P](https://avatars.githubusercontent.com/u/40272544?v=4)](https://github.com/Lukasz93P "Lukasz93P (20 commits)")

---

Tags

asyncasynchronouseventsrabbitmqmessagingmessage-brokermessage processing

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/lukasz93p-async-message-channel/health.svg)

```
[![Health](https://phpackages.com/badges/lukasz93p-async-message-channel/health.svg)](https://phpackages.com/packages/lukasz93p-async-message-channel)
```

###  Alternatives

[enqueue/enqueue

Message Queue Library

19820.0M56](/packages/enqueue-enqueue)[nuwber/rabbitevents

The Nuwber RabbitEvents package

120515.8k3](/packages/nuwber-rabbitevents)[prolic/humus-amqp

PHP-AMQP library with RabbitMQ Extensions

76205.4k5](/packages/prolic-humus-amqp)[kdyby/rabbitmq

Integrates php-amqplib with RabbitMq and Nette Framework

30693.1k4](/packages/kdyby-rabbitmq)[orisai/scheduler

Cron job scheduler - with locks, parallelism and more

4037.1k4](/packages/orisai-scheduler)[marwanalsoltany/amqp-agent

An elegant wrapper around the famous php-amqplib for 90% use case.

161.8k](/packages/marwanalsoltany-amqp-agent)

PHPackages © 2026

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