1. Go to this page and download the library: Download zaeem2396/laravel-nats 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/ */
zaeem2396 / laravel-nats example snippets
use LaravelNats\Laravel\Facades\NatsV2;
NatsV2::publish('orders.created', ['order_id' => 123], ['X-Request-Id' => 'req-1']);
use LaravelNats\Laravel\Facades\NatsV2;
use LaravelNats\Subscriber\InboundMessage;
NatsV2::subscribe('orders.created', function (InboundMessage $message): void {
$payload = $message->envelopePayload();
logger()->info('Order received', (array) $payload);
});
while (true) {
NatsV2::process(null, 1.0);
}