1. Go to this page and download the library: Download babelqueue/laravel library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use BabelQueue\Contracts\ShouldQueuePolyglot;
final class CreateOrder implements ShouldQueuePolyglot
{
public function __construct(private int $orderId, private float $amount) {}
public function getBabelUrn(): string
{
return 'urn:babel:orders:created';
}
public function toPayload(): array
{
return ['order_id' => $this->orderId, 'amount' => $this->amount];
}
}
CreateOrder::dispatch(1042, 99.90)->onConnection('bq-redis');
use BabelQueue\Facades\BabelQueue;
BabelQueue::publish('urn:babel:orders:created', ['order_id' => 1042, 'amount' => 99.90]);
final class OnOrderCreated
{
// $data, $meta, $traceId and $message are injected by name.
public function handle(array $data, array $meta, string $traceId): void
{
logger()->info('order created', ['id' => $data['order_id'], 'trace' => $traceId]);
}
// Optional: called once when retries are exhausted.
public function failed(array $data, ?\Throwable $e): void
{
report($e);
}
}
'dead_letter' => [
'enabled' => true,
'suffix' => '.dlq', // failures from "orders" go to "orders.dlq"
],