The library was written for a private project, it's not as flexible as you might want.
For today I think that this package is WIP and I do not recommend production use.
Have fun!
Laravel RabbitMQ has some cool features
You can easily use the send
method, which takes two parameters. The first is the content of the message, and the second is the endpoint that the Consumer listens to
public function sendNotification(Order $order, ProducerService $service): void
{
$service->send(
['order_id' => $order->id],
'order.shipped.notification'
);
}
Simple file route/queue.php
// Define a standard "endpoint"
Queue::listen('cart.created', CartCreated::class);
// Or group it as you prefer
Queue::name('order.')->group(function () {
Queue::listen('shipped', OrderShipped::class);
Queue::listen('confirmed', OrderConfirmed::class);
});
// Pass dispatchable job
Queue::listen('order.confirmed', OrderConfirmedJob::class);
// Pass dispatchable event
Queue::listen('order.confirmed', OrderConfirmedEvent::class);
// Pass class and method as in standard Laravel routing
Queue::listen('order.confirmed', [OrderConfirmed::class, 'sendNotification']);
// You can also pass a invokable class
Queue::listen('order.confirmed', InvokableOrderConfirmed::class);
// You can also use closure for local testing
Queue::listen('order.confirmed', function (string|array $message) {
return $message; // ['order_id' => 1]
});
php artisan rabbitmq:listen