网站地图    收藏   

主页 > php专栏 > php综合实列 >

Laravel使用RabbitMQ的方法示例

来源:自学PHP网    时间:2019-08-01 11:26 作者:小飞侠 阅读:

[导读] Laravel使用RabbitMQ的方法示例...

导语

安装

  • docker-compose stop workspace php-fpm php-worker
  • docker-compose up -d workspace php-fpm php-worker rabbitmq扩展包安装以及配置
  • 接下来在燾onfig/queue.php 文件中燾onnections 添加爎abbitmq 配置,根据情况自行修改
    'rabbitmq' => [
    
      'driver' => 'rabbitmq',
    
      /*
       * Set to "horizon" if you wish to use 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
       * - \EnqueueAmqpBunny\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('RABBITMQ_QUEUE', 'default'),
    
      'options' => [
    
        'exchange' => [
    
          'name' => env('RABBITMQ_EXCHANGE_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://www.rabbitmq.com/tutorials/amqp-concepts.html
           */
    
          'type' => env('RABBITMQ_EXCHANGE_TYPE', \Interop\Amqp\AmqpTopic::TYPE_DIRECT),
          'passive' => env('RABBITMQ_EXCHANGE_PASSIVE', false),
          'durable' => env('RABBITMQ_EXCHANGE_DURABLE', true),
          'auto_delete' => env('RABBITMQ_EXCHANGE_AUTODELETE', false),
          '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 https://www.rabbitmq.com/tutorials/amqp-concepts.html
           */
    
          'passive' => env('RABBITMQ_QUEUE_PASSIVE', false),
          'durable' => env('RABBITMQ_QUEUE_DURABLE', true),
          'exclusive' => env('RABBITMQ_QUEUE_EXCLUSIVE', false),
          'auto_delete' => env('RABBITMQ_QUEUE_AUTODELETE', false),
          'arguments' => env('RABBITMQ_QUEUE_ARGUMENTS'),
        ],
      ],
    
      /*
       * Determine the number of seconds to sleep if there's an error communicating with rabbitmq
       * If set to false, it'll throw an exception rather than doing the sleep for X seconds.
       */
    
      'sleep_on_error' => env('RABBITMQ_ERROR_SLEEP', 5),
    
      /*
       * Optional SSL params if an SSL connection is used
       * Using an SSL connection will also require to configure your RabbitMQ to enable SSL. More details can be founds here: https://www.rabbitmq.com/ssl.html
       */
    
      'ssl_params' => [
        'ssl_on' => env('RABBITMQ_SSL', false),
        '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),
        'passphrase' => env('RABBITMQ_SSL_PASSPHRASE', null),
      ],
    
    ],
    
    
    
    RABBITMQ_WORKER=horizon
    RABBITMQ_HOST=rabbitmq
    RABBITMQ_PORT=5672
    RABBITMQ_LOGIN=guest
    RABBITMQ_PASSWORD=guest
    RABBITMQ_QUEUE=default
    
    

    参考资料:laravel-queue-rabbitmq

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

    自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

    京ICP备14009008号-1@版权所有www.zixuephp.com

    网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

    添加评论