简体   繁体   中英

Laravel queue listeners on multiple machines on the same queue

I currently have a multi-server Laravel setup. I have multiple servers that are load balanced and share a database.

Each instance is also running a queue listener. I want to be able to dispatch two types of jobs:

  1. A job that is only run once (eg send email, update a model, etc)
  2. A job that is run on ALL queue listeners (eg delete a file from the filesystem)

The first I think is quite simple to implement, but unsure how to go about implementing the second one. Any ideas?

You can make a queue listener or worker handle specific queues. For example run a queue listener or worker to handle emails queue.

php artisan queue:listen --queue=emails
php artisan queue:work --queue=emails

You can now dispatch jobs to a this queue

dispatch((new Job)->onQueue('emails'));

This can help you setup multiple listeners/workers to handle different queues based on your requirements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM