https://github.com/mle86/php-wq-amqp
An AMQP adapter for WQ (https://github.com/mle86/php-wq)
https://github.com/mle86/php-wq-amqp
amqp amqp-client php php-library rabbitmq rabbitmq-client work-queue wq
Last synced: 7 days ago
JSON representation
An AMQP adapter for WQ (https://github.com/mle86/php-wq)
- Host: GitHub
- URL: https://github.com/mle86/php-wq-amqp
- Owner: mle86
- License: mit
- Created: 2018-07-07T16:33:39.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2025-09-11T09:51:37.000Z (9 months ago)
- Last Synced: 2025-09-11T12:43:54.319Z (9 months ago)
- Topics: amqp, amqp-client, php, php-library, rabbitmq, rabbitmq-client, work-queue, wq
- Language: PHP
- Size: 47.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WQ-AMQP (`mle86/wq-amqp`)
This package contains the PHP class
mle86\WQ\WorkServerAdapter\\AMQPWorkServer.
It supplements the
[**mle86/wq**](https://github.com/mle86/php-wq) package
by implementing its `WorkServerAdapter` interface.
It connects to an AMQP server
such as [RabbitMQ](https://www.rabbitmq.com/)
using the [php-amqplib/php-amqplib](https://github.com/php-amqplib/php-amqplib) package.
It creates durable queues in the default exchange (“”) for immediate-delivery jobs
and the durable “`_phpwq._delayed`” queue in the custom “`_phpwq._delay_exchange`” exchange for delayed jobs.
Jobs stored with `storeJob()` are always durable as well.
Empty queues or exchanges won't be deleted automatically.
# Version and Compatibility
This is
**version 1.4.0**
of `mle86/wq-amqp`.
It was developed for
version 1.0.0
of `mle86/wq`
and should be compatible
with all of its future 1.x versions as well.
# Installation and Dependencies
```
$ composer require mle86/wq-amqp
```
It requires PHP 8.0+.
It depends on
[mle86/wq](https://github.com/mle86/php-wq)
and [php-amqplib/php-amqplib](https://github.com/php-amqplib/php-amqplib),
which in turn requires the
[mbstring](https://php.net/manual/book.mbstring.php),
[sockets](https://php.net/manual/book.sockets.php),
and
[bcmath](https://php.net/manual/book.bc.php)
PHP extensions.
# Class reference
class mle86\WQ\WorkServerAdapter\\AMQPWorkServer implements WorkServerAdapter
* public function __construct (AMQPStreamConnection $connection)
Constructor.
Takes an already-configured `AMQPStreamConnection` instance to work with.
Does not attempt to establish a connection itself –
use the `connect()` factory method for that instead.
* public static function connect ($host = 'localhost', $port = 5672, $user = 'guest', $password = 'guest', $vhost = '/', $insist = false, $login\_method = 'AMQPLAIN', $login\_response = null, $locale = 'en\_US', $connection\_timeout = 3.0, $read\_write\_timeout = 3.0, $context = null, $keepalive = false, $heartbeat = 0)
Factory method.
See [AMQPStreamConnection::__construct](https://github.com/php-amqplib/php-amqplib/blob/v2.7.2/PhpAmqpLib/Connection/AMQPStreamConnection.php#L8)
for the parameter descriptions.
Interface methods
which are documented in the [`WorkServerAdapter`](https://github.com/mle86/php-wq/blob/master/doc/Ref_WorkServerAdapter_interface.md) interface:
* public function storeJob (string $workQueue, Job $job, int $delay = 0)
* public function getNextQueueEntry ($workQueue, int $timeout = DEFAULT\_TIMEOUT): ?QueueEntry
* public function buryEntry (QueueEntry $entry)
* public function requeueEntry (QueueEntry $entry, int $delay, string $workQueue = null)
* public function deleteEntry (QueueEntry $entry)
# Usage example
```php
processNextJob("mail", function(Job $job) {
$job->...;
});
}
```
This executes all jobs available in the local AMQP server's “`mail`” queue, forever.
It will however abort if one of the jobs throws an exception –
you might want to add a logging try-catch block around the `processNextJob()` call
as shown in [WQ's “Quick Start” example](https://github.com/mle86/php-wq#quick-start).