-
Notifications
You must be signed in to change notification settings - Fork 0
06.Consumer
Muhammet ŞAFAK edited this page Aug 31, 2024
·
2 revisions
Consumers are pieces of code that run workers that try to consume messages from a queue.
$queue = new \App\Queues\NotificationQueue();
// Consume
$queue->consume(function (MessageInterface $message) {
try {
$payload = $message->getPayload();
sleep(2);
return true;
} catch (\Exception $e) {
return false;
}
});
Consume takes a callable worker of type Closure
as a parameter. This Closure must return a value that can be cast as boolean. If the worker function completes without returning anything, the message is considered failed. For detailed information about Worker, see the Worker section. See Worker
Note : If the message is a Job Message, the worker you defined to consume it will not run. Instead, the message's worker method will be run.