This package implements the standard logic for sending webhooks using laravel queues, and also allows you to create event subscribers for deferred sending to each of them
Install package via composer :
$ composer require sirsova/laravel-webhooks
After installation you need to register service provider in config/app.php
:
'providers' => [
...
SirSova\Webhooks\ServiceProvider::class,
]
Also for using package configs you need to execute script, which publish config/webhooks.php
to root config directory:
$ php artisan vendor:publish --tag=webhooks_config
For coping package migrations to root path of migration :
$ php artisan vendor:publish --tag=webhooks-migrations
ProcessMessage
: Dispatch a message to the message processor, which queues the webhooks to all subscribers by event nameProcessWebhook
: Dispatch a webhook to the webhook channel, which send message on the given url (subscriber url)
use Illuminate\Contracts\Bus\QueueingDispatcher;
use SirSova\Webhooks\Jobs\ProcessMessage;
use SirSova\Webhooks\Message;
...
$busDispatcher = app(QueueingDispatcher::class);
$message = new Message('event-type', ['foo' => 'bar']);
$job = new ProcessMessage($message);
//queued message example
$busDispatcher->dispatchToQueue($job->onQueue('webhooks'));
//dispatching in time message
$busDispatcher->dispatch($job);
//queued webhook example
$webhook = new Webhook($message, 'https://example.com');
$job = new ProcessWebhook($webhook);
$busDispatcher->dispatchToQueue($job->onQueue('webhooks'));
Each message would be processed by event specific subscribers.
MessageProcessor
will create a new Webhook for each subscriber and dispatch them to queue(see Config).
You can easily manipulate with self written solution by overriding binding for WebhookChannel
and MessageProcessor
in DI container.
$ composer test
Please see CHANGELOG for more information what has changed recently.
The MIT License (MIT). Please see License File for more information.