首页 > 作文

Laravel使用RabbitMQ的方法示例

更新时间:2023-04-07 07:42:20 阅读: 评论:0

导语

rabbitmq 想必大家都有了解,不做多介绍来。这里实现的是用 rabbitmq 作为 larvel 队列的驱动,替代 redis。下面以 laradock 中安装示例。

安装

切换到laradock 目录,将.env 中关于install_amqp 的值修改为truedocker-compo stop workspace php-fpm php-workerdocker-compo build workspace php-fpm php-worker rabbitmqdocker-compo up -d workspace php-fpm php-worker rabbitmq

扩展包安装以及配置

进入到workspace 容器中,在项目目录安装扩展包compor require vladimir-yuldashev/laravel-queue-rabbitmq接下来在config/queue.php 文件中connections 添加rabbitmq 配置,根据情况自行修改
'rabbitmq' => [  'driver' => 'rabbitmq',  /*   * t to "horizon" if you wish to u laravel horizon.   */  'worker' => env('rabbitmq_worker', 'default'),  'dsn' => env('rabbitmq_dsn', null),  /*   * could be one a class that implements \interop\amqp\amqpconnectionfactory for example:   * - \enqueueamqpext\amqpconnectionfactory if you install enqueue/amqp-ext   * - \enqueueamqplib\amqpconnectionfactory if you install enqueue/amqp-lib   * - \en长歌行古诗原文queueamqpbunny\amqpconnectionfactory if you install enqueue/amqp-bunny   */  'factory_class' => enqueue\amqplib\amqpconnectionfactory::class,  'host' => env('rabbitmq_host', '127.0.0.1'),  'port' => env('rabbitmq_port', 5672),  'vhost' => env('rabbitmq_vhost', '/'),  'login' => env('rabbitmq_login', 'guest'),  'password' => env('rabbitmq_password', 'guest'),  'queue' => env('ra高危行业企业安全生产费用财务管理暂行办法bbitmq_queue', 'default'),  'options' => [    'exchange' => [      'name' => env('rabbitmq_exc心理咨询师二级培训hange_name'),      /*       * determine if exchange should be created if it does not exist.       */      'declare' => env('rabbitmq_exchange_declare', true),      /*       * read more about possible values at https://ww宽带ip地址查询w.rabbitmq.com/tutorials/amqp-concepts.html       */      'type' => env('rabbitmq_exchange_type', \interop\amqp\amqptopic::type_direct),      'passive' => env('rabbitmq_exchange_passive', fal),      'durable'大学生成长报告1000字 => env('rabbitmq_exchange_durable', true),      'auto_delete' => env('rabbitmq_exchange_autodelete', fal),      'arguments' => env('rabbitmq_exchange_arguments'),    ],    'queue' => [      /*       * determine if queue should be created if it does not exist.       */      'declare' => env('rabbitmq_queue_declare', true),      /*       * determine if queue should be binded to the exchange created.       */      'bind' => env('rabbitmq_queue_declare_bind', true),      /*       * read more about possible values at /d/file/titlepic/amqp-concepts.html       */      'passive' => env('rabbitmq_queue_passive', fal),      'durable' => env('rabbitmq_queue_durable', true),      'exclusive' => env('rabbitmq_queue_exclusive', fal),      'auto_delete' => env('rabbitmq_queue_autodelete', fal),      'arguments' => env('rabbitmq_queue_arguments'),    ],  ],  /*   * determine the number of conds to sleep if there's an error communicating with rabbitmq   * if t to fal, it'll throw an exception rather than doing the sleep for x conds.   */  'sleep_on_error' => env('rabbitmq_error_sleep', 5),  /*   * optional ssl params if an ssl connection is ud   * using an ssl connection will also require to configure your rabbitmq to enable ssl. more details can be founds here: /d/file/titlepic/ssl.html   */  'ssl_params' => [    'ssl_on' => env('rabbitmq_ssl', fal),    'cafile' => env('rabbitmq_ssl_cafile', null),    'local_cert' => env('rabbitmq_ssl_localcert', null),    'local_key' => env('rabbitmq_ssl_localkey', null),    'verify_peer' => env('rabbitmq_ssl_verify_peer', true),    'passphra' => env('rabbitmq_ssl_passphra', null),  ],],

在.env 中修改queue_connection 为rabbitmq ,并添加以下值

rabbitmq_worker=horizonrabbitmq_host=rabbitmqrabbitmq_port=5672rabbitmq_login=guestrabbitmq_password=guestrabbitmq_queue=default

有两个值说明一下,因为是在 laradock 中,所以rabbitmq_host 设置为rabbitmq ;如果之前使用了laravel horizon,那么rabbitmq_worker 的设置为horizon 就可以了。

参考资料:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持www.887551.com。

本文发布于:2023-04-07 07:42:17,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/37a3a331f68ae6fcf4f98d34d5d88789.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:Laravel使用RabbitMQ的方法示例.doc

本文 PDF 下载地址:Laravel使用RabbitMQ的方法示例.pdf

上一篇:选择器的权重
下一篇:返回列表
标签:设置为   的是   歌行   是在
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图