PHPackages                             comlaude/laravel-amqp - 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. comlaude/laravel-amqp

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

comlaude/laravel-amqp
=====================

AMQP wrapper for Laravel and Lumen to publish and consume messages

2.3.0(3mo ago)414.1k↓22.7%MITPHPPHP ^7.4|^8.0

Since Sep 11Pushed 3mo ago7 watchersCompare

[ Source](https://github.com/ComLaude/laravel-amqp)[ Packagist](https://packagist.org/packages/comlaude/laravel-amqp)[ RSS](/packages/comlaude-laravel-amqp/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (28)Used By (0)

ComLaude/laravel-amqp
=====================

[](#comlaudelaravel-amqp)

Simple PhpAmqpLib wrapper for interaction with RabbitMQ

[![Build Status](https://camo.githubusercontent.com/9a56d1233a0651d46f24e111d27d19ff8b1727f3de208564ad8e70f428b6dcb8/68747470733a2f2f6170692e7472617669732d63692e636f6d2f436f6d4c617564652f6c61726176656c2d616d71702e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/ComLaude/laravel-amqp)[![Latest Stable Version](https://camo.githubusercontent.com/0205caab0d845e014029bf546610104355c5323e9b9638b0c0d025a305c808ec/68747470733a2f2f706f7365722e707567782e6f72672f636f6d6c617564652f6c61726176656c2d616d71702f76)](//packagist.org/packages/comlaude/laravel-amqp)[![License](https://camo.githubusercontent.com/54c88773575b19883ab55e245315c92ee0e399858f182648f857ea868f34fa7d/68747470733a2f2f706f7365722e707567782e6f72672f636f6d6c617564652f6c61726176656c2d616d71702f6c6963656e7365)](//packagist.org/packages/comlaude/laravel-amqp)

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

[](#installation)

### Composer

[](#composer)

Add the following to your require part within the composer.json:

```
"comlaude/laravel-amqp": "^1.0.0"
```

```
$ php composer update
```

or

```
$ php composer require comlaude/laravel-amqp

```

Integration
-----------

[](#integration)

### Lumen

[](#lumen)

Create a **config** folder in the root directory of your Lumen application and copy the content from **vendor/comlaude/laravel-amqp/config/amqp.php** to **config/amqp.php**.

Adjust the properties to your needs.

```
return [

    'use' => 'production',

    'properties' => [

        'production' => [
            'host'                  => 'localhost',
            'port'                  =>  5672,
            'username'              => '',
            'password'              => '',
            'vhost'                 => '/',
            'use_tls'               => false,
            'connect_options'       => [],
            'connect_context'       => null, // (optional) Stream context for TLS connections https://www.php.net/manual/en/context.ssl.php

            /*
            |--------------------------------------------------------------------------
            | An example configuration to connect with TLS, using a custom set of context rules
            |--------------------------------------------------------------------------
            |
            |    'host'                  => 'localhost',
            |    'port'                  =>  5671,
            |    'username'              => '',
            |    'password'              => '',
            |    'vhost'                 => '/',
            |    'use_tls'               => true,
            |    'connect_options'       => [],
            |    'connect_context'       => stream_context_create([
            |        'ssl' => [
            |            'verify_peer' => true,
            |            'verify_peer_name' => true,
            |            'allow_self_signed' => false,
            |        ],
            |    ]),
            */

            'register_pcntl_heartbeat_sender' => false, // Signal based heartbeat sender https://github.com/php-amqplib/php-amqplib/pull/815

            'exchange'              => 'amq.topic',
            'exchange_type'         => 'topic',
            'exchange_passive'      => false,
            'exchange_durable'      => true,
            'exchange_auto_delete'  => false,
            'exchange_internal'     => false,
            'exchange_nowait'       => false,
            'exchange_properties'   => [],

            'queue_force_declare'   => false,
            'queue_passive'         => false,
            'queue_durable'         => true,          // only change when not using quorum queues
            'queue_exclusive'       => false,
            'queue_auto_delete'     => false,         // only change when not using quorum queues
            'queue_nowait'          => false,
            'queue_properties'      => [
                'x-ha-policy' => ['S', 'all'],
                'x-queue-type' => ['S', 'quorum'],
                // 'x-dead-letter-exchange' => ['S', 'amq.topic-dlx'], // if provided an exchange and queue (queue_name-dlx) will be automatically declared
                // 'x-delivery-limit' => ['I', 5],                     // the delivery limit will be set on the relevant queue but not the DLX queue itself
            ],
            'queue_acknowledge_is_final' => true,     // if important work is done inside a consumer after the acknowledge call, this should be false
            'queue_reject_is_final'      => true,     // if important work is done inside a consumer after the reject call, this should be false

            'consumer_tag'              => '',
            'consumer_no_local'         => false,
            'consumer_no_ack'           => false,
            'consumer_exclusive'        => false,
            'consumer_nowait'           => false,
            'timeout'                   => 0,        // seconds
            'persistent'                => false,
            'persistent_restart_period' => 0,        // seconds
            'request_accepted_timeout'  => 0.5,      // seconds in decimal accepted
            'request_handled_timeout'   => 5,        // seconds in decimal accepted
            'request_must_be_handled'   => false,    // if true, the request must be handled by the consumer even if the requestor is not listening

            'qos'                   => true,
            'qos_prefetch_size'     => 0,
            'qos_prefetch_count'    => 1,
            'qos_a_global'          => false,

            /*
            |--------------------------------------------------------------------------
            | An example binding set up when declaring exchange and queues
            |--------------------------------------------------------------------------
            |'bindings' => [
            |    [
            |        'queue'    => 'example',
            |        'routing'  => 'example.route.key',
            |    ],
            |],
            */
        ],

    ],

];
```

Register the Lumen Service Provider in **bootstrap/app.php**:

```
/*
|--------------------------------------------------------------------------
| Register Service Providers
|--------------------------------------------------------------------------
*/

//...

$app->configure('amqp');
$app->register(ComLaude\Amqp\LumenServiceProvider::class);

//...
```

Add Facade Support for Lumen 5.2+

```
//...
$app->withFacades(true, [
    'ComLaude\Amqp\Facades\Amqp' => 'Amqp',
]);
//...
```

### Laravel

[](#laravel)

Open **config/app.php** and add the service provider and alias:

```
'ComLaude\Amqp\AmqpServiceProvider',
```

```
'Amqp' => 'ComLaude\Amqp\Facades\Amqp',
```

Publishing a message
--------------------

[](#publishing-a-message)

### Push message with routing key

[](#push-message-with-routing-key)

```
Amqp::publish('routing-key', 'message');
```

### Push message with routing key and overwrite properties

[](#push-message-with-routing-key-and-overwrite-properties)

```
Amqp::publish('routing-key', 'message' , ['exchange' => 'amq.direct']);
```

Consuming messages
------------------

[](#consuming-messages)

### Consume messages forever

[](#consume-messages-forever)

```
Amqp::consume(function ($message) {

    var_dump($message->body);

    Amqp::acknowledge($message);

});
```

### Consume messages, with custom settings

[](#consume-messages-with-custom-settings)

```
Amqp::consume(function ($message) {

   var_dump($message->body);

   Amqp::acknowledge($message);

}, [
    'timeout' => 2,
    'vhost'   => 'vhost3',
    'queue'   => 'queue-name',
    'persistent' => true // required if you want to listen forever
]);
```

Fanout example
--------------

[](#fanout-example)

### Publishing a message

[](#publishing-a-message-1)

```
Amqp::publish('', 'message' , [
    'exchange_type' => 'fanout',
    'exchange' => 'amq.fanout',
]);
```

Disable publishing
------------------

[](#disable-publishing)

This is useful for development and sync requirements, if you are using observers or events to trigger messages over AMQP you may want to temporarily disable the publishing of messages. When turning the publishing off the publish method will silently drop the message and return.

### Check state

[](#check-state)

```
if(Amqp::isEnabled()) {
    // It is going to publish
}
```

### Disable

[](#disable)

```
Amqp::disable();
```

### Enable

[](#enable)

```
Amqp::enable();
```

Remote procedure call server and client
---------------------------------------

[](#remote-procedure-call-server-and-client)

RPC is potentially an anti-pattern in a microservices world so do not use it carelessly, nevertheless sometimes you just need that request-response behaviour and you're willing to accept its limitations. Simply return a response from within a consumer handler, if the message is a request from a client, the response will automatically be routed to the correct requestor. There are 2 configurable timeouts to prevent infinite-blocking waits.

`request_accepted_timeout` - time to wait for confirmation from server that a job is being worked on, this is a check if anybody is listening at all and should be quite small

`request_handled_timeout` - time to wait for the full request to be completed (all messages), be careful to ensure this is large enough if your job is long-lasting or if the number of messages to be handled is large

### Server

[](#server)

```
Amqp::consume(function ($message) {

   Amqp::acknowledge($message);

   return "I handled this message " . $message->getBody();

});
```

### Client

[](#client)

```
Amqp::request('example.routing.key', [

    'message1',
    'message2',

], function ($message) {

   echo("The remote server said " . $message->getBody());

});

// Or for single message requests you can just do
$response = Amqp::requestWithResponse('example.routing.key', 'quickly');
// $response is already the message content as a string "I handled this message quickly"
```

### Consume messages, with dead letter exchange configured

[](#consume-messages-with-dead-letter-exchange-configured)

When using the `x-dead-letter-exchange` parameter in queue properties the package will additionally:

- declare the &lt;queue\_name&gt;-dlx queue
- declare the exchange itself

When the consumer fails or requeues the message for 5 times the message will instead be routed to this new queue via the dead letter exchange.

```
Amqp::consume(function ($message) {

   var_dump($message->body);

   Amqp::acknowledge($message);

}, [
    'timeout' => 2,
    'vhost'   => 'vhost3',
    'queue'   => 'my-example-queue',
    'persistent' => true // required if you want to listen forever
    'queue_properties'      => [
        'x-ha-policy' => ['S', 'all'],
        'x-queue-type' => ['S', 'quorum'],
        'x-dead-letter-exchange' => ['S', 'amq.topic-dlx'], // will auto-declare queue named my-example-queue-dlx
        'x-delivery-limit' => ['I', 5], // after 5 deliveries the message is routed to my-example-queue-dlx
    ],
]);
```

Credits
-------

[](#credits)

- Some concepts were used from

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

52

—

FairBetter than 96% of packages

Maintenance82

Actively maintained with recent releases

Popularity29

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 87.8% 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 ~79 days

Recently: every ~47 days

Total

26

Last Release

92d ago

Major Versions

0.1.0 → 1.0.02020-09-15

1.2.0 → 2.0.02022-10-06

PHP version history (4 changes)0.0.1PHP &gt;=7.0

1.1.3PHP ^7.0|^8.0

2.0.0PHP ^7.3|^8.0

2.0.2PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/bbb703d9485c0d3ad76567fd5a979d1f3b0d3725afd3eaf0af4f83aca77cdf20?d=identicon)[david.krizanic](/maintainers/david.krizanic)

---

Top Contributors

[![SloEddy](https://avatars.githubusercontent.com/u/1764938?v=4)](https://github.com/SloEddy "SloEddy (36 commits)")[![justasSendrauskas](https://avatars.githubusercontent.com/u/6369740?v=4)](https://github.com/justasSendrauskas "justasSendrauskas (4 commits)")[![danhanly-comlaude](https://avatars.githubusercontent.com/u/215669605?v=4)](https://github.com/danhanly-comlaude "danhanly-comlaude (1 commits)")

---

Tags

laravelpackagelumenrabbitmqAMQPComLaude

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/comlaude-laravel-amqp/health.svg)

```
[![Health](https://phpackages.com/badges/comlaude-laravel-amqp/health.svg)](https://phpackages.com/packages/comlaude-laravel-amqp)
```

###  Alternatives

[bschmitt/laravel-amqp

AMQP wrapper for Laravel and Lumen to publish and consume messages

2752.3M7](/packages/bschmitt-laravel-amqp)[mookofe/tail

RabbitMQ and PHP client for Laravel and Lumen that allows you to add and listen queues messages just simple

5552.5k](/packages/mookofe-tail)[kunalvarma05/laravel-rabbitmq

Work with RabbitMQ in Laravel.

1853.7k](/packages/kunalvarma05-laravel-rabbitmq)[iamfarhad/laravel-rabbitmq

A robust RabbitMQ driver for Laravel Queue with advanced message queuing, reliable delivery, and high-performance async processing capabilities

3215.6k](/packages/iamfarhad-laravel-rabbitmq)

PHPackages © 2026

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