dougua9328 2016-12-25 10:14
浏览 1699
已采纳

什么是Laravel队列连接和onQueue方法? [关闭]

I just finished to read laravel documentation about queues and I dont understand somethings.

  1. What are these queues connections ?
    What they do?
    What is the difference between 'beanstalkd' , 'sqs', 'iron' and 'redis' ?

  2. What onQueue method does?
    I read that you can with named queues tou can categorize the workers, but what the workers are? jon classes?
    For what it's good?

  • 写回答

1条回答 默认 最新

  • doudg60800 2016-12-25 11:23
    关注

    Queues as we know follow the First In/First Out terminology. This means that whoever is first in the queue is meant to be taken care of first. They are generally run in the background via consoles/shells.

    What are these queues connections?

    Therefore, database/storage engines that store the entries for processing the queues are required. Nowadays, people generally use redis (site) or sqs (a service given by Amazon Web Services) as one of these databases/storage engines.

    In Laravel, we have queue drivers which store the necessary details (like the hostname, the port number, username, password) to connect to these databases/storage engines.

    What onQueue method does?

    OnQueue method is defined inside the Queueable trait (\Illuminate\Bus\Queueable.php) which is used to specify the queue on which a particular job/event has to to be pushed to.

    Basically, when you go config/queue.php, you'll find a connections array. Something like...

    'redis' => [
      'driver' => 'redis',
      'connection' => 'default',
      'queue' => 'default',
      'expire' => 60,
    ],
    

    The second last element of the it is queue which is used for naming the queue of that particular connection. By using different queue names, you can parallelize your jobs/events and run them on different queue connections for faster processing.

    So, one queue can be used to send mails, and the other for maybe... checking something in your database and then storing the data into cache based on the output.

    Also, before you ask anymore questions, I'd suggest you to try this out yourself. You can start out with redis and install it in your local machine. Once you're through with that, you can start it by the redis-server command and then in your laravel project run things from your queue by php artisan queue:listen command.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题