thyseus/saloon-iggy-connector
最新稳定版本:0.1.1
Composer 安装命令:
composer require thyseus/saloon-iggy-connector
包简介
Connect a PHP application to iggy using saloon
README 文档
README
Send and poll messages from https://iggy.apache.org/ via php / https://docs.saloon.dev/
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
<?php
$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); // <-- debug
$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
<?php
return Application::configure(basePath: dirname(__DIR__))
->withSchedule(function (Schedule $schedule): void {
// or ->everySecond() if sub-minute is supported by your env
$schedule->command('poll:iggy')->everyMinute();
});
Source:
https://github.com/apache/iggy/blob/master/core/server/server.http
统计信息
- 总下载量: 2.75k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-02-11