composer require b2pweb/bdf-queue-bundle
config/bundles.php:
Bdf\QueueBundle\BdfQueueBundle::class => ['all' => true],
.env:
BDF_QUEUE_CONNETION_URL=gearman://root@127.0.0.1?client-timeout=10
config/packages/bdf_queue.yaml with a minimal setup:
bdf_queue:
default_connection: 'gearman'
connections:
gearman:
url: '%env(resolve:BDF_QUEUE_CONNETION_URL)%'
bdf_queue.yaml:
destinations:
bus:
url: 'queue://gearman/bus'
Bdf\QueueBundle\Producer\ProducerInterface service:
use Bdf\QueueBundle\Producer\ProducerInterface;
class MyService {
public function __construct(private ProducerInterface $producer) {}
public function sendMessage() {
$this->producer->send('bus', 'Hello, Queue!');
}
}
Producer-Consumer Pattern
ProducerInterface to send messages to destinations.
$producer->send('destination_name', $message, ['priority' => 1]);
ReceiverFactoryProviderInterface) to handle messages.
services:
MyReceiverFactory:
class: App\Receiver\MyReceiverFactory
tags: ['bdf_queue.receiver_factory']
Connection Management
ConnectionDriverConfiguratorInterface for unsupported drivers (e.g., Redis, RabbitMQ).
class RedisConfigurator implements ConnectionDriverConfiguratorInterface {
public function configure(ConnectionDriverFactory $factory) {
$factory->addDriver('redis', new RedisDriver());
}
}
autoconfigure (set autoconfigure: true in bdf_queue.yaml).Middleware Integration
class MyReceiverFactory implements ReceiverFactoryProviderInterface {
public function getReceiverFactories() {
$factory = new ReceiverFactory();
$factory->addMiddleware(new LoggingMiddleware());
return [$factory];
}
}
Dynamic Destinations
destinations:
dynamic_bus:
url: '%env(resolve:DYNAMIC_QUEUE_URL)%'
symfony/messenger for hybrid workflows.
# config/packages/messenger.yaml
framework:
messenger:
transports:
async: '%env(MESSENGER_TRANSPORT_DSN)%'
retry option in consumer config for failed jobs.
destinations:
bus:
consumer:
retry: 3
auto_handle: true for message-based routing (requires target hints in messages).Connection URL Parsing
{driver}+{vendor}://{user}:{password}@{host}:{port}/{queue}.gearman://user:pass@localhost:4730/bus (not gearman://localhost/bus).host, port, etc., if the URL is malformed.Serializer Mismatch
bdf or bdf_json serializers, ensure the consumer and producer agree on the format.Bdf\Queue\Serializer\SerializerFactory for supported IDs (native, bdf, bdf_json).Consumer Stuck on Empty Queue
stop_when_empty: true halts consumption if no messages arrive within the wait duration.stop_when_empty: false for long-running consumers.Memory Limits
memory option in consumer config kills the process if exceeded.memory_get_usage()).Middleware Order
ReceiverFactory. Place critical middleware (e.g., validation) early.class LogMiddleware implements MiddlewareInterface {
public function handle(ReceiveContext $context, callable $next) {
\Log::info('Message received', ['body' => $context->getMessage()->getBody()]);
return $next($context);
}
}
Bdf\QueueBundle\ConnectionFactory\ConnectionFactory service to test connections:
$connection = $connectionFactory->createConnection('gearman');
if (!$connection->isConnected()) {
throw new \RuntimeException('Connection failed');
}
ParameterBag throws exceptions for invalid config. Use symfony/var-dumper to inspect parsed config:
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
$config = $container->getParameter('bdf_queue');
dump($config);
Bdf\Queue\Serializer\SerializerInterface and register via bdf_queue.serializer service ID:
services:
app.custom_serializer:
class: App\Serializer\CustomSerializer
tags: ['bdf_queue.serializer']
Bdf\Queue\Connection\DriverInterface and configure via ConnectionDriverConfiguratorInterface.class CustomReceiverFactory implements ReceiverFactoryProviderInterface {
public function getReceiverFactories() {
return [new class extends ReceiverFactory {
protected function createReceiver() {
return new CustomReceiver();
}
}];
}
}
bdf_queue.message.sent, bdf_queue.message.received) via Symfony’s event dispatcher.%env(resolve:VAR_NAME)% to resolve variables early (avoids runtime errors).bdf_queue:
connections:
gearman:
options:
client-timeout: 30 # Overrides URL param if present
autoconfigure: true in bdf_queue.yaml to auto-register services implementing ReceiverFactoryProviderInterface or ConnectionDriverConfiguratorInterface. Disable if you need explicit control.How can I help you explore Laravel packages today?