thyseus / saloon-iggy-connector
Connect a PHP application to iggy using saloon
0.1.0
2025-02-11 17:48 UTC
Requires
- saloonphp/laravel-plugin: ^3.5
- saloonphp/saloon: ^3.10.1
This package is not auto-updated.
Last update: 2025-03-26 15:27:35 UTC
README
Installation
composer require thyseus/iggy-saloon-connector
Configuration
config/services.php:
'iggy' => [
'base_url' => env('IGGY_BASE_URL'),
'username' => env('IGGY_USERNAME'),
'password' => env('IGGY_PASSWORD'),
'consumer' => env('IGGY_CONSUMER'),
],
put your production credentials in your .env
:
IGGY_BASE_URL=https://my-iggy-instance.com
IGGY_USERNAME=iggy
IGGY_PASSWORD=secret
IGGY_CONSUMER=consumer-id-of-my-application
Usage: post message to stream
$request = new PostMessagesRequest('my-stream', 'my-topic');
$request->body()->merge([
'partitioning' => [
'kind' => 'balanced',
'value' => 'balanced',
],
'messages' => [
[
'id' => 0,
'payload' => base64_encode('{"Linux": "Rules"}')
]
],
]);
$response = $iggy->send($request);
Usage: get messages from stream, single shot as CLI command
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Thyseus\IggyConnector\GetMessagesRequest;
use Thyseus\IggyConnector\IggyConnector;
class PollIggyCommand extends Command
{
protected $signature = 'poll:iggy';
protected $description = 'Poll iggy';
public function handle()
{
$iggy = new IggyConnector();
$request = new GetMessagesRequest('my-desired-stream', 'my-desired-topic');
$response = $iggy->send($request);
// $response = $iggy->debug(die: true)->send($request);
$messages = $response->json()['messages'];
foreach ($messages as $message) {
$payload = base64_decode($message['payload']);
$this->line("Message received: $payload");
ProcessMessageJob::dispatch($payload);
}
}
}
Usage: Periodic pull of messages using CLI command before
bootstrap/app.php
return Application::configure(basePath: dirname(__DIR__))
->withSchedule(function (Schedule $schedule): void {
$schedule->command('poll:iggy')->everySecond();
});
Source:
https://github.com/iggy-rs/iggy/blob/master/server/server.http