alexlcdee/messenger-tarantool
Symfony Messenger transport for Tarantool Queue. Install via Composer and use either tarantool/client or the ext-tarantool PECL extension to connect to Tarantool and run messenger messages through a Tarantool-backed queue.
Installation:
composer require alexlcdee/messenger-tarantool
Ensure ext-tarantool is installed in your PHP environment.
Configuration:
Add the service provider and bind the client in config/app.php:
'providers' => [
// ...
Alexlcdee\MessengerTarantool\TarantoolServiceProvider::class,
],
Publish Config (if needed):
php artisan vendor:publish --provider="Alexlcdee\MessengerTarantool\TarantoolServiceProvider"
Configure config/messenger-tarantool.php with your Tarantool connection details (host, port, user/password if required).
First Use Case: Dispatch a message to Tarantool via Laravel's Messenger:
use Alexlcdee\MessengerTarantool\TarantoolMessage;
// In a controller or command:
dispatch(new TarantoolMessage('your_space', 'your_box', [
'key' => 'unique_key',
'data' => ['message' => 'Hello, Tarantool!']
]));
Synchronous vs. Asynchronous:
TarantoolMessage for async dispatch (via Laravel's queue system).TarantoolClient directly:
use Alexlcdee\MessengerTarantool\TarantoolClient;
public function __construct(TarantoolClient $client) {
$this->client = $client;
}
public function syncOperation() {
$this->client->call('space', 'function', ['args']);
}
Handling Responses:
$response = $this->client->call('space', 'get', [123]);
$data = $response[1] ?? null; // Tarantool responses are [success, data, error]
Batch Operations:
TarantoolClient::call() with batch requests:
$this->client->call('space', 'insert', [
{1, {name: 'Alice', age: 30}},
{2, {name: 'Bob', age: 25}}
]);
Error Handling:
try {
$this->client->call('space', 'unsafe', ['risky']);
} catch (\Tarantool\Exception\TarantoolException $e) {
Log::error("Tarantool error: " . $e->getMessage());
}
config/queue.php to use messenger-tarantool as a driver for async operations.retry-after for transient failures:
dispatch((new TarantoolMessage(...))->retryAfter(30));
config/messenger-tarantool.php to trace requests/responses.Connection Management:
$this->client->connect(); // Re-establish connection
connection events to handle reconnects globally.Schema Mismatches:
if (!isset($data['required_field'])) {
throw new \InvalidArgumentException("Missing field");
}
Async Race Conditions:
TarantoolMessage dispatches don’t wait for Tarantool to process. Use unique keys or callbacks to correlate responses.Deprecated Methods:
ext-tarantool) may have breaking changes. Test thoroughly.'debug' => true in config to log raw requests/responses.console.log for errors if messages aren’t processed.var_dump($response) to inspect Tarantool’s response structure (e.g., [true, data] vs [false, error]).Custom Message Classes:
Extend TarantoolMessage to add metadata or validation:
class CustomTarantoolMessage extends TarantoolMessage {
public function __construct($space, $box, array $data, public string $customField) {
parent::__construct($space, $box, $data);
}
}
Middleware: Add middleware to transform messages before dispatch:
$bus->pipe(function ($message, $next) {
$message->data['timestamp'] = now()->toDateTimeString();
return $next($message);
});
Fallback Drivers: Implement a fallback to Redis or database if Tarantool is unavailable:
try {
$this->client->call(...);
} catch (\Exception $e) {
// Fallback logic
}
How can I help you explore Laravel packages today?