alphasoft-fr/messenger-filesystem-transport
FilesystemTransport is a transport for Symfony Messenger based on the file system. It allows for handling asynchronous messages without using a database or an external message broker such as RabbitMQ or Redis. This is a simple and lightweight solution, ideal for small to medium-sized projects.
FilesystemTransport is a transport for Symfony Messenger based on the file system. It allows for handling asynchronous messages without using a database or an external message broker such as RabbitMQ or Redis. This is a simple and lightweight solution, ideal for small to medium-sized projects.
To install the package via Composer, use the following command:
composer require alphasoft-fr/messenger-filesystem-transport
Messenger Doctrine), which can improve application performance.To activate the bundle, you need to add it manually in the config/bundles.php file of your Symfony project:
// config/bundles.php
return [
// ...
\AlphaSoft\Messenger\FilesystemTransport\AsMessengerFilesystemTransportBundle::class => ['all' => true],
];
Here is an example configuration for using FilesystemTransport :
# config/packages/messenger.yaml
framework:
messenger:
failure_transport: failed
transports:
filesystem:
dsn: 'filesystem://'
options:
directory: '%kernel.project_dir%/var/messages'
log : false
failed:
dsn: 'filesystem://'
options:
directory: '%kernel.project_dir%/var/messages/failed'
In this example, messages will be stored in the var/messages directory of your Symfony project.
filesystem:// DSN.failed/ subdirectory for easier management.To send asynchronous messages, you can use the transport like any other Symfony Messenger transport:
use Symfony\Component\Messenger\MessageBusInterface;
class NotificationService
{
private $bus;
public function __construct(MessageBusInterface $bus)
{
$this->bus = $bus;
}
public function sendNotification(NotificationMessage $message): void
{
$this->bus->dispatch($message);
}
}
The "log" option must be enabled:
# config/packages/messenger.yaml
framework:
messenger:
failure_transport: failed
transports:
filesystem:
dsn: 'filesystem://'
options:
directory: '%kernel.project_dir%/var/messages'
log : true
failed:
dsn: 'filesystem://'
options:
directory: '%kernel.project_dir%/var/messages/failed'
When a message is processed successfully, a log entry is added in processed.log:
{
"timestamp": "2024-10-18 14:32:05",
"message_id": "20241018_143205_123456",
"message_type": "App\\Message\\NotificationMessage",
"status": "processed"
}
In the event of a failed message, a similar entry is added in failed.log to facilitate error tracking and analysis.
To run unit tests, clone the repository and use PHPUnit:
git clone https://github.com/alphasoft-fr/messenger-filesystem-transport.git
cd messenger-filesystem-transport
composer install
php vendor/bin/phpunit
This project is licensed under the MIT. You are free to use, modify, and redistribute it under the terms of this license.
Contributions are welcome! If you want to propose improvements or report an issue, feel free to open an issue or submit a pull request.
git checkout -b feature/new-feature).git commit -am 'Add new feature').git push origin feature/new-feature).FilesystemTransport est un transport pour Symfony Messenger basé sur le système de fichiers. Il permet de gérer des messages asynchrones sans avoir recours à une base de données ou à un broker de message externe tel que RabbitMQ ou Redis. C'est une solution simple et légère, idéale pour des projets de petite à moyenne envergure.
Pour installer le package via Composer, utilisez la commande suivante :
composer require alphasoft-fr/messenger-filesystem-transport
Messenger Doctrine), ce qui peut améliorer les performances de l'application.Pour activer le bundle, vous devez l'ajouter manuellement dans le fichier config/bundles.php de votre projet Symfony :
// config/bundles.php
return [
// ...
\AlphaSoft\Messenger\FilesystemTransport\AsMessengerFilesystemTransportBundle::class => ['all' => true],
];
Voici un exemple de configuration pour utiliser FilesystemTransport :
# config/packages/messenger.yaml
framework:
messenger:
failure_transport: failed
transports:
filesystem:
dsn: 'filesystem://'
options:
directory: '%kernel.project_dir%/var/messages'
log : false
failed:
dsn: 'filesystem://'
options:
directory: '%kernel.project_dir%/var/messages/failed'
Dans cet exemple, les messages seront stockés dans le répertoire var/messages de votre projet Symfony.
filesystem://failed/ pour faciliter leur gestion.Pour envoyer des messages asynchrones, vous pouvez utiliser le transport comme n'importe quel autre transport de Symfony Messenger :
use Symfony\Component\Messenger\MessageBusInterface;
class NotificationService
{
private $bus;
public function __construct(MessageBusInterface $bus)
{
$this->bus = $bus;
}
public function sendNotification(NotificationMessage $message): void
{
$this->bus->dispatch($message);
}
}
L'option "log" doit etre activé :
# config/packages/messenger.yaml
framework:
messenger:
failure_transport: failed
transports:
filesystem:
dsn: 'filesystem://'
options:
directory: '%kernel.project_dir%/var/messages'
log : true
failed:
dsn: 'filesystem://'
options:
directory: '%kernel.project_dir%/var/messages/failed'
Lorsqu'un message est traité avec succès, une entrée de log est ajoutée dans processed.log :
{
"timestamp": "2024-10-18 14:32:05",
"message_id": "20241018_143205_123456",
"message_type": "App\\Message\\NotificationMessage",
"status": "processed"
}
En cas de message échoué, une entrée similaire est ajoutée dans failed.log pour faciliter le suivi et l'analyse des erreurs.
Pour exécuter les tests unitaires, clonez le dépôt et utilisez PHPUnit :
git clone https://github.com/alphasoft-fr/messenger-filesystem-transport.git
cd messenger-filesystem-transport
composer install
php vendor/bin/phpunit
Ce projet est sous licence MIT. Vous êtes libre de l'utiliser, de le modifier et de le redistribuer sous les termes de cette licence.
Les contributions sont les bienvenues ! Si vous souhaitez proposer des améliorations ou signaler un problème, n'hésitez pas à ouvrir une issue ou à soumettre une pull request.
git checkout -b feature/nouvelle-fonctionnalite).git commit -am 'Ajoute une nouvelle fonctionnalité').git push origin feature/nouvelle-fonctionnalite).How can I help you explore Laravel packages today?