本文以lumen *** 作, laravel请自行参阅文档
安装:
composer require bschmitt/laravel-amqp
复制 vendor/bschmitt/laravel-amqp/config/amqp.php to config/amqp.php
编辑你的config/amqp.php 符合你的rabbitmq
编辑: bootstrap/app.php:
加入
$app->configure('amqp'); $app->register(BschmittAmqpLumenServiceProvider::class);
生产者命令: app/Console/Commands/PublishAmqpCommand.php
argument('msg') , ['queue' => 'queue-name']); //Amqp::publish('routing-key2', 'message2' , ['exchange' => 'amq.topic']); } }
消费者命令:
info($message->body); $resolver->acknowledge($message); }, [ 'persistent' => true, // required if you want to listen forever ]); } }
修改: app/Console/Kernel.php
use AppConsoleCommandsPublishAmqpCommand; use AppConsoleCommandsConsumeAmqpCommand; ... protected $commands = [ Other::class, PublishAmqpCommand::class, ConsumeAmqpCommand::class, ];
测试:
先执行消费者命令:
php artisan zj:consumeamqp
再执行生产者命令:
php artisan zj:publishamqp "hello mq"
在消费者端可以看到输出
hello mq
参考:
bschmitt/laravel-amqp - Packagist
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)