1. Go to this page and download the library: Download kuncen/mcs-laravel-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/ */
kuncen / mcs-laravel-rabbitmq example snippets
use Kuncen\MCSLaravel\RabbitMQ\Services\RabbitMQPublisher;
class UserController extends Controller
{
public function store(RabbitMQPublisher $publisher)
{
$publisher->publish(
payload: [
'user_id' => 1,
'name' => 'John Doe'
],
routingKey: 'user.created'
);
return response()->json(['status' => 'Message sent']);
}
}
class UserCreatedListener implements RabbitMQListener
{
public static function queue(): string
{
return 'user.created';
}
public function handle(array $payload): void
{
// Your business logic here
}
}
use Kuncen\MCSLaravel\RabbitMQ\Services\RabbitMQPublisher;
class UserController extends Controller
{
public function store(RabbitMQPublisher $publisher)
{
$publisher->publish(
payload: [
'user_id' => 1,
'name' => 'John Doe'
],
routingKey: 'user.created'
);
return response()->json(['status' => 'Message sent']);
}
}
class UserCreatedListener implements RabbitMQListener
{
public static function queue(): string
{
return 'user.created';
}
public function handle(array $payload): void
{
// Logic bisnis di sini
}
}