PHP code example of shipmate-io / laravel-shipmate
1. Go to this page and download the library: Download shipmate-io/laravel-shipmate 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/ */
return [
/*
* The message queues that are available to your service.
*/
'queues' => [
'default' => env('SHIPMATE_DEFAULT_MESSAGE_QUEUE_NAME'),
],
/*
* The file within your code base that defines your message handlers.
*/
'message_handlers' => base_path('routes/messages.php'),
/*
* Whether to register the routes
use Shipmate\LaravelShipmate\MessageQueue\ShouldPublish;
class UserCreated implements ShouldPublish
{
public function publishOn(): string
{
return 'default';
}
public function publishAs(): string
{
return 'user.created';
}
public function publishWith(): array
{
return [
'first_name' => 'John',
'last_name' => 'Doe',
];
}
}
use Shipmate\Shipmate\MessageQueue\Message;
class HandleUserCreatedMessage
{
public function __invoke(Message $message): void
{
$firstName = $message->payload['first_name'];
//
}
}
class HandleUserCreatedMessage
{
public function handle(Message $message): void
{
$firstName = $message->payload['first_name'];
//
}
}
class HandleUserCreatedMessage
{
public function execute(Message $message): void
{
$firstName = $message->payload['first_name'];
//
}
}