PHP code example of pablicio / mirabel-rabbitmq
1. Go to this page and download the library: Download pablicio/mirabel-rabbitmq 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/ */
pablicio / mirabel-rabbitmq example snippets
use Mirabel\RabbitMQ\Event;
final class OrderReceived extends Event
{
const ROUTING_KEY = 'orders.received';
}
(new OrderReceived(['id' => 123]))->publish();
use Mirabel\RabbitMQ\Envelope;
use Mirabel\RabbitMQ\Worker;
final class ChargeOrder extends Worker
{
const QUEUE = 'billing.orders-received',
EVENTS = [OrderReceived::class],
ATTEMPTS = 4,
RETRY_DELAY = 5_000;
public function handle(Envelope $envelope): void
{
charge($envelope->body['id']); // return normally → ack; throw → retry
}
}
(new ChargeOrder())->subscribe();