Install the Bundle
composer require 3slab/vdm-library-bundle
Add to config/bundles.php:
return [
// ...
Vdm\LibraryBundle\VdmLibraryBundle::class => ['all' => true],
];
Configure Required Services
Edit config/packages/vdm_library.yaml (auto-generated) to define:
vdm_collect (HTTP/FTP/SFTP sources)vdm_store (Elasticsearch/Doctrine)vdm_backbone (broker transport like RabbitMQ, AMQP, etc.)First Use Case: HTTP Pull Consumer
Define a message handler class (e.g., src/MessageHandler/ProcessHttpDataHandler.php):
namespace App\MessageHandler;
use Vdm\LibraryBundle\Message\CollectHttpMessage;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
class ProcessHttpDataHandler
{
public function __invoke(CollectHttpMessage $message)
{
// Process $message->getData()
return new ProduceToStoreMessage($processedData);
}
}
Trigger a Job Dispatch a message via CLI or controller:
php bin/console messenger:consume vdm_collect_http -vv
graph TD
A[Trigger HTTP Pull] --> B[CollectHttpMessage]
B --> C[ProcessHttpDataHandler]
C --> D[ProduceToStoreMessage]
D --> E[Elasticsearch/Doctrine Store]
CollectHttpMessage → Custom Handler → ProduceToStoreMessage.vdm_collect.http:
vdm_collect:
http:
sources:
my_source:
url: "https://api.example.com/data"
retry:
max_attempts: 3
delay: 1000
$message = new ProduceToStoreMessage($data);
$this->messageBus->dispatch($message);
# config/packages/messenger.yaml
framework:
messenger:
transports:
vdm_backbone: '%env(VDM_BROKER_DSN)%'
routing:
'App\Message\ProduceToStoreMessage': vdm_backbone
Stopwatch or integrate with Prometheus:
use Symfony\Component\Stopwatch\Stopwatch;
class ProcessHttpDataHandler {
public function __invoke(CollectHttpMessage $message, Stopwatch $stopwatch) {
$event = $stopwatch->start('http_processing');
// ... processing logic ...
$event->stop();
}
}
StoreEntity with @Vdm\Store\Annotation\Indexed for Elasticsearch sync:
#[ORM\Entity]
#[Vdm\Store\Annotation\Indexed(indexName: 'my_index')]
class Product {
// ...
}
vdm_collect.ftp:
vdm_collect:
ftp:
sources:
remote_files:
host: "ftp.example.com"
username: "%env(FTP_USER)%"
password: "%env(FTP_PASS)%"
directory: "/incoming"
file_pattern: "*.csv"
namespace App\Message;
use Vdm\LibraryBundle\Message\BaseMessage;
class CustomCollectMessage extends BaseMessage {
public function __construct(string $source, array $options) {
parent::__construct($source, $options);
}
}
Broker Connection Issues
VDM_BROKER_DSN in .env and check broker health:
php bin/console debug:container vdm.backbone.producer
Elasticsearch Indexing Delays
vdm_store.elasticsearch.sync is enabled and the StoreEntity has the @Indexed annotation.HTTP Retry Overload
retry:
max_attempts: 3
delay: 1000
multiplier: 2 # Exponential backoff
Enable Messenger Debugging:
php bin/console messenger:failed:list
php bin/console messenger:failed:remove ALL
Log Message Flow:
# config/packages/monolog.yaml
monolog:
handlers:
messenger:
type: stream
path: "%kernel.logs_dir%/messenger.log"
level: debug
Custom Metrics
Vdm\LibraryBundle\Monitoring\MetricCollector to add custom metrics:
namespace App\Monitoring;
use Vdm\LibraryBundle\Monitoring\MetricCollector;
class CustomMetricCollector extends MetricCollector {
public function collectCustomMetric(string $name, $value) {
$this->metrics[$name] = $value;
}
}
Message Transformers
MessageBus middleware to transform messages:
use Symfony\Component\Messenger\Middleware\HandleMessage;
class TransformMessageMiddleware {
public function __invoke(HandleMessage $handle, $message) {
if ($message instanceof CollectHttpMessage) {
$message->setData($this->transform($message->getData()));
}
return $handle($message);
}
}
Event Listeners
vdm.library.message.processed events:
namespace App\EventListener;
use Vdm\LibraryBundle\Event\MessageProcessedEvent;
use Symfony\Component\EventDispatcher\Attribute\AsEventListener;
#[AsEventListener(event: 'vdm.library.message.processed')]
class LogProcessedMessageListener {
public function __invoke(MessageProcessedEvent $event) {
// Log or notify on message processing
}
}
vdm_backbone.transport is set, the bundle defaults to symfony://async, which may not suit high-throughput scenarios.vdm_store.elasticsearch.client is properly configured (e.g., elasticsearch://user:pass@localhost:9200).passive: true in the config to avoid firewall issues:
ftp:
sources:
remote_files:
passive: true
How can I help you explore Laravel packages today?