muxtorov98 / rabbitmq-universal
Universal RabbitMQ Queue Worker for PHP frameworks (Laravel, Symfony, Yii2)
Installs: 21
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/muxtorov98/rabbitmq-universal
Requires
- php: >=8.1
- ext-sockets: *
- php-amqplib/php-amqplib: ^3.7 || ^4.0
- symfony/console: ^5.0|^6.0|^7.0
- vlucas/phpdotenv: ^5.5
Suggests
- laravel/framework: Required only for Laravel integration
- symfony/framework-bundle: Required only for Symfony integration
- yiisoft/yii2: Required only for Yii2 console integration
README
Universal RabbitMQ Queue System — bu PHP 8+ uchun ishlab chiqilgan framework-agnostic kutubxona bo‘lib,
Laravel, Symfony va Yii2 loyihalarida xabar yuborish (publish) va qabul qilish (consume) jarayonlarini bir xil sintaksisda amalga oshirish imkonini beradi.
🚀 Asosiy xususiyatlar
✅ Laravel, Symfony va Yii2 bilan avtomatik moslashadi
✅ .env orqali sozlanadi — qo‘shimcha config talab etilmaydi
✅ Auto reconnect & retry mexanizmi
✅ QoS, prefetch, confirm mode (ACK) qo‘llab-quvvatlanadi
✅ PSR-4 autoload va PSR-3 logging
✅ Worker backgroundda doimiy ishlaydi (Supervisor yoki Docker bilan)
📦 O‘rnatish
composer require muxtorov98/rabbitmq-universal:v2.1.8 --ignore-platform-reqs
docker compose exec php composer require muxtorov98/rabbitmq-universal:v2.1.8 --ignore-platform-reqs
⚙️ .env konfiguratsiyasi
Loyha ildizida .env fayl yarating:
RABBITMQ_HOST='localhost' RABBITMQ_PORT=5672 RABBITMQ_USER='muxtorov' RABBITMQ_PASS='5upris#1eWata2ped' RABBITMQ_VHOST='/' RABBITMQ_PREFETCH=10 RABBITMQ_SSL=false # Worker handler fayllar joylashgan joy HANDLER_PATH='app/Handlers'
🧩 Umumiy Worker va Publisher misoli
🔧 Handler (har uchala framework uchun bir xil)
laravel Handler
app/Handlers/EmailHandler.php:
<?php namespace App\Handlers; use RabbitMQQueue\Core\QueueHandlerInterface; use RabbitMQQueue\Core\QueueChannel; use RabbitMQQueue\Core\RabbitPublisher; #[QueueChannel('notification_queue')] class NotificationHandler implements QueueHandlerInterface { public function handle(array $message): void { echo "📩 Notification received: " . json_encode($message, JSON_UNESCAPED_UNICODE) . PHP_EOL; } }
⚙️ Laravel integratsiyasi
🪄 1. Avtomatik yuklash
Paket avtomatik tarzda RabbitMQServiceProvider ni yuklaydi, qo‘shimcha ro‘yxatdan o‘tkazish talab etilmaydi.
🏃 2. Worker ishga tushirish
php artisan rabbit:worker
docker compose exec php php artisan rabbit:worker
⚙️ Yii2 integratsiyasi
⚙️ 1. console/config/main.php faylida controllerMap sozlovi
'controllerMap' => [ 'worker' => [ 'class' => \RabbitMQQueue\Frameworks\Yii2\WorkerController::class, ], ],
Yii2 Handler
console/Handlers/EmailHandler.php;
<?php namespace console\Handlers; use RabbitMQQueue\Core\QueueHandlerInterface; use RabbitMQQueue\Core\QueueChannel; use RabbitMQQueue\Core\RabbitPublisher; #[QueueChannel('email_queue')] class EmailHandler implements QueueHandlerInterface { public function handle(array $message): void { echo "📩 Email received: " . json_encode($message, JSON_UNESCAPED_UNICODE) . PHP_EOL; } }
🏃 2. Worker ishga tushirish
php yii worker/start
⚙️ Symfony integratsiyasi
⚙️ 1. services.yaml konfiguratsiyasi
config/services.yaml fayliga quyidagilarni qo‘shing:
RabbitMQQueue\Frameworks\Symfony\: resource: '../vendor/muxtorov98/rabbitmq-universal/src/Frameworks/Symfony/*' tags: [ 'console.command' ]
symfony Handler
src/Handlers/LogHandler.php;
<?php namespace App\Handlers; use RabbitMQQueue\Core\QueueHandlerInterface; use RabbitMQQueue\Core\QueueChannel; use RabbitMQQueue\Core\RabbitPublisher; #[QueueChannel('log_queue')] class LogHandler implements QueueHandlerInterface { public function handle(array $message): void { echo "📩 log received: " . json_encode($message, JSON_UNESCAPED_UNICODE) . PHP_EOL; } }
🏃 2. Worker ishga tushirish
php bin/console rabbit:worker:start
✉️ Publish qilish (hamma frameworklarda bir xil)
use RabbitMQQueue\Core\RabbitPublisher; $publisher = new RabbitPublisher(); $publisher->publish('email_queue', [ 'to' => 'user@example.com', 'subject' => 'Universal publish test!' ]);
laravel
- app/Console/Commands/RabbitPublishCommand.php
<?php namespace App\Console\Commands; use Illuminate\Console\Command; use RabbitMQQueue\Core\RabbitPublisher; class RabbitPublishCommand extends Command { protected $signature = 'rabbit:publish {queue} {--data=}'; protected $description = 'Publish a message to RabbitMQ queue (from Laravel)'; public function handle() { $queue = $this->argument('queue'); $data = $this->option('data') ? json_decode($this->option('data'), true) : ['text'=>'Salom from Laravel']; $publisher = new RabbitPublisher(); $publisher->publish($queue, $data); $this->info("📩 Message published to queue '{$queue}' from Laravel: " . json_encode($data, JSON_UNESCAPED_UNICODE)); } }
php artisan rabbit:publish log_queue --data='{"status":"processed","to":"user@example.com","text":"Salom from Laravel"}'
symfony
- src/Command/RabbitPublishCommand.php
<?php namespace App\Command; use RabbitMQQueue\Core\RabbitPublisher; use Symfony\Component\Console\Attribute\AsCommand; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; #[AsCommand( name: 'rabbit:publish', description: 'Publish a message to RabbitMQ queue' )] class RabbitPublishCommand extends Command { protected function configure(): void { $this ->addArgument('queue', InputArgument::REQUIRED, 'Queue name') ->addArgument('data', InputArgument::REQUIRED, 'JSON encoded data'); } protected function execute(InputInterface $input, OutputInterface $output): int { $queue = $input->getArgument('queue'); $jsonData = $input->getArgument('data'); $data = json_decode($jsonData, true); if (json_last_error() !== JSON_ERROR_NONE) { $output->writeln('<error>❌ JSON format xato:</error> ' . json_last_error_msg()); return Command::FAILURE; } $publisher = new RabbitPublisher(); $publisher->publish($queue, $data); $output->writeln("✅ Xabar jo'natildi: <info>$queue</info>"); return Command::SUCCESS; } }
php bin/console rabbit:publish notification_queue '{"event":"user_registered","user_id":12345,"text":"Salom from Symfony"}'
yii
- console/controllers/RabbitPublishController.php
<?php namespace console\controllers; use yii\console\Controller; use RabbitMQQueue\Core\RabbitPublisher; use yii\helpers\Json; class RabbitPublishController extends Controller { public $data; public function options($actionID) { return ['data']; } public function actionIndex($queue) { $data = $this->data ? Json::decode($this->data) : []; $publisher = new RabbitPublisher(); $publisher->publish($queue, $data); $this->stdout("Message published to queue '{$queue}' from Yii2\n"); } }
php yii rabbit-publish email_queue --data='{"to":"user@example.com","subject":"Yii2 to Laravel"}'