bbit/sqs-command-queue-bundle
Installation Run:
composer require bbit/sqs-command-queue-bundle:dev-master
(Note: Use dev-master as the package is outdated; pin to a specific commit if needed.)
Enable Bundle
Add to app/AppKernel.php:
new BBIT\SqsCommandQueueBundle\BBITSqsCommandQueueBundle(),
Configure
Add to app/config/config.yml:
bbit_sqs_command_queue:
aws_sqs_key: "%aws_sqs_key%"
aws_sqs_secret: "%aws_sqs_secret%"
aws_sqs_region: "eu-central-1"
aws_sqs_queue: "https://sqs.eu-central-1.amazonaws.com/xx11xx11/xx-xx"
Store credentials in .env or parameters.yml (never commit secrets).
First Use Case Dispatch a command via a service:
$this->get('sqs_queue')->addCommand('app/console cache:clear');
Or directly via container:
php app/console sqs:send-command "app/console cache:clear"
Dispatching Commands
$this->get('sqs_queue')->addCommand('app/console my:command --option=value');
public function onKernelRequest(GetResponseEvent $event) {
$this->container->get('sqs_queue')->addCommand('app/console my:async-task');
}
array_map to queue multiple commands (e.g., for batch processing).Worker Management
php app/console bbit:sqs:worker
(Run in a separate process/terminal; use screen/tmux for persistence.)[program:sqs-worker]
command=php /path/to/app/console bbit:sqs:worker
autostart=true
autorestart=true
user=www-data
Command Integration
Command class and queue them like built-in commands.
Example:
// src/AppBundle/Command/MyAsyncCommand.php
namespace AppBundle\Command;
use Symfony\Component\Console\Command\Command;
class MyAsyncCommand extends Command { ... }
Queue with:
$this->get('sqs_queue')->addCommand('app:my-async-command');
Error Handling
BBIT\SqsCommandQueueBundle\Command\CommandInterface to add retry logic for failed commands.Monitoring
// Override BBIT\SqsCommandQueueBundle\Worker\Worker
public function executeCommand($command) {
$this->logger->info("Executing: $command");
parent::executeCommand($command);
}
Outdated Package
aws/aws-sdk-php to v3).league/flysystem-aws-s3-v3) for SQS if needed.symfony/messenger + symfony/amqp-messenger for RabbitMQ.php-amqplib for RabbitMQ/SQS via STOMP.AWS Credentials
config.yml is unsafe..env files or AWS IAM roles (for EC2 instances).
Example .env:
AWS_SQS_KEY=AKIAXXXXXXXXXXXXXXXX
AWS_SQS_SECRET=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Worker Stuck on Failures
ApproximateNumberOfMessagesNotVisible.// Override BBIT\SqsCommandQueueBundle\Worker\Worker
public function executeCommand($command) {
try {
parent::executeCommand($command);
} catch (\Exception $e) {
$this->logger->error("Failed to execute $command: " . $e->getMessage());
throw $e; // Re-throw to trigger SQS retry
}
}
Visibility Timeout
Command Timeouts
Process component for subprocesses.Environment-Specific Queues
Use different SQS queues per environment (e.g., dev-queue, prod-queue):
# config_dev.yml
bbit_sqs_command_queue:
aws_sqs_queue: "https://sqs.eu-central-1.amazonaws.com/xx11xx11/dev-queue"
Priority Queues
$this->get('sqs_queue')->addCommand('high:app:cache:clear');
Then filter in the worker:
if (strpos($command, 'high:') === 0) {
$this->executeHighPriority($command);
}
Testing
docker run -it -p 4566:4566 localstack/localstack
Update config to point to LocalStack’s SQS endpoint.Performance Tuning
public function run() {
while ($messages = $this->sqs->receiveMessages()) {
foreach ($messages as $message) {
$this->executeCommand($message->getBody());
$this->sqs->deleteMessage($message);
}
}
}
Security
sqs:SendMessage, sqs:ReceiveMessage).Extending the Bundle
BBIT\SqsCommandQueueBundle\Worker\Worker to add features like:
sqs.command.send and sqs.command.execute events (if the bundle supports them; may require patching).How can I help you explore Laravel packages today?