AMQP is a painless Way to Use RabbitMQ with Laravel

AMQP is a painless Way to Use RabbitMQ with Laravel

The anik/amqp package by Syed Sirajul Islam Anik is a php-amqplib wrapper that eases the consumption of RabbitMQ.

You can use this package with Laravel, Lumen, and Laravel Zero. At the time of writing, you will need to configure the service provider manually (a pull request was submitted for package discovery).

We recently wrote about a Laravel Queue Driver for RabbitMQ package, which is a queue driver that enables you to use RabbitMQ with the Laravel queue API. You can think of anik/amqp more as a general package with conveniences on top of php-amqplib, and the RabbitMQ queue driver as a drop-in driver for Laravel queues.

From the package’s readme, here’s how you might publish a message:

app('amqp')->publish('Message to direct exchange', 'routing-key', [
    'exchange' => [
        'type'    => 'direct',
        'name'    => '',

And here’s how you might consume a message:

use Anik\Amqp\ConsumableMessage;

// AmqpManager::consume($consumerHandler, $bindingKey, $config);
app('amqp')->consume(function (ConsumableMessage $message) {
    echo $message->getStream() . PHP_EOL;
}, 'routing-key', [
    'connection' => 'my-connection-name',
    'exchange'   => [
        'type'    => 'direct',
        'name'    => '',
    'queue' => [
        'name'         => '',
        'declare'      => true,
        'exclusive'    => false,
    'qos' => [
        'enabled'            => true,
        'qos_prefetch_count' => 5,

For the documentation (and for a nice overview of RabbitMQ) check out the package author’s post: RabbitMQ for PHP Developers. You can learn more about this package, get full installation instructions, and view the source code on GitHub at ssi-anik/amqp.

Filed in: News


Join 31,000+ others and never miss out on new tips, tutorials, and more.

Laravel News Partners

Laravel Jobs

Laravel Senior Developer
Remote, Canada Only
BeMo Academic Consulting
Senior Fullstack Developer / Architect (w/m/d)
Remote / Munich - Germany GmbH
Medior full stack developer (Laravel)
Deventer (or remote) in the Netherlands, Dutch speaking required.
Senior Full Stack PHP Developer (Laravel)
Senior Laravel Developer