https://github.com/roadrunner-php/jobs
:electric_plug: RoadRunner Jobs (Queue) SDK
https://github.com/roadrunner-php/jobs
consumer dispatcher jobs php queue roadrunner
Last synced: 6 months ago
JSON representation
:electric_plug: RoadRunner Jobs (Queue) SDK
- Host: GitHub
- URL: https://github.com/roadrunner-php/jobs
- Owner: roadrunner-php
- License: mit
- Created: 2021-07-23T11:01:30.000Z (over 4 years ago)
- Default Branch: 4.x
- Last Pushed: 2024-11-30T15:42:19.000Z (over 1 year ago)
- Last Synced: 2025-03-29T04:07:43.641Z (12 months ago)
- Topics: consumer, dispatcher, jobs, php, queue, roadrunner
- Language: PHP
- Homepage: https://roadrunner.dev
- Size: 261 KB
- Stars: 23
- Watchers: 3
- Forks: 13
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: .github/CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: .github/CODE_OF_CONDUCT.md
- Security: .github/SECURITY.md
Awesome Lists containing this project
README
# RoadRunner Jobs Plugin
[](https://packagist.org/packages/spiral/roadrunner-jobs)
[](https://packagist.org/packages/spiral/roadrunner-jobs)
[](https://github.com/spiral/roadrunner-jobs/actions)
[](https://github.com/spiral/roadrunner-jobs/actions)
[](https://codecov.io/gh/roadrunner-php/jobs/)
[](https://packagist.org/packages/spiral/roadrunner-jobs)
[](https://github.styleci.io/repos/388772135?branch=master)

This repository contains the codebase PHP bridge using RoadRunner Jobs plugin.
## Installation
To install application server and Jobs codebase
```bash
composer require spiral/roadrunner-jobs
```
You can use the convenient installer to download the latest available compatible version of RoadRunner assembly:
```bash
composer require spiral/roadrunner-cli --dev
vendor/bin/rr get
```
## Configuration
First you need to add at least one jobs adapter to your RoadRunner configuration. For example, such a configuration would be quite feasible to run:
```yaml
rpc:
listen: tcp://127.0.0.1:6001
server:
command: php consumer.php
relay: pipes
jobs:
consume: [ "local" ]
pipelines:
local:
driver: memory
config:
priority: 10
prefetch: 10000
```
> **Note**
> Read more about all available drivers on the [documentation](https://docs.roadrunner.dev/queues-and-jobs/overview-queues) page.
After starting the server with this configuration, one driver named `local` will be available to you.
## Usage
### Producer
The following code will allow writing and reading an arbitrary value from the RoadRunner server.
```php
connect('local');
// Create task prototype with default headers
$task = $queue->create('ping', '{"site": "https://example.com"}') // Create task with "echo" name
->withHeader('attempts', 4) // Number of attempts to execute the task
->withHeader('retry-delay', 10); // Delay between attempts
// Push "echo" task to the queue
$task = $queue->dispatch($task);
var_dump($task->getId() . ' has been queued');
```
### Consumer
The Consumer processes tasks from RoadRunner server and responds based on the processing outcome:
- `ack` - is used for positive acknowledgements.
- `nack` - is used for negative acknowledgements.
- `requeue` - is used for requeuing the task.
The behavior of the `nack` method depends on its implementation by the queue driver. It can accept an additional
parameter **redelivery**; if it is passed and set to **true**, the task will be requeued. However, not all drivers
support this functionality. If the redelivery parameter is not passed, set to **false**, or the queue driver's
implementation does not support it, the task will not be requeued.
```php
$task->nack(message: $reason, redelivery: true);
```
The `requeue` method is implemented by RoadRunner and does not depend on the queue driver. It allows you to resend
the task to **the end of the queue** and add additional headers to the task.
```php
$task->withHeader('attempts', (string) ($attempts + 1))->requeue($exception);
```
The `nack` and `requeue` methods have the ability to specify a **delay** for requeuing the task. To do this, call
the `withDelay` method and pass the desired value before invoking the `nack` or `requeue` methods.
```php
$task->withDelay(10)->requeue($exception);
```
```php
waitTask()) {
try {
$name = $task->getName(); // "ping"
$queue = $task->getQueue(); // "local"
$driver = $task->getDriver(); // "memory"
$payload = $task->getPayload(); // {"site": "https://example.com"}
// Process task
$task->ack();
} catch (\Throwable $e) {
$task->requeue($e);
}
}
```
## License
The MIT License (MIT). Please see [`LICENSE`](./LICENSE) for more information. Maintained
by [Spiral Scout](https://spiralscout.com).