Laravel - 作业在一台服务器上分派,在另一台服务器上处理 [英] Laravel - Job dispatched on one server, handled on another

查看:50
本文介绍了Laravel - 作业在一台服务器上分派,在另一台服务器上处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究 Laravel 应用程序的日志记录方面,amd 计划将数据发送到 SQS 以便稍后检索.但是,我想将作业从我的生产服务器分派到 AWS 队列,但随后有一个队列在单独的日志服务器上工作,该服务器侦听队列.

I'm working on the logging aspect of a Laravel application, amd was planning to send the data to an SQS for retrieval at a later time. However, I would like to dispatch the job from my production server to the AWS Queue, but then have a Queue working on a separate Logging server which listens to the Queue.

我了解如何设置 Queue worker 以监听 Queue,但是,Laravel 的 Jobs 是自我处理的.因此,当 Logging 服务器上的 worker 从 SQS 检索消息时,它会在相同的命名空间(具有相同的类名)中寻找作业来处理它.有没有办法以不同的方式处理这个问题,或者我只需要将日志服务器上的作业处理程序命名为与生产服务器上的作业调度程序相同.

I understand how to setup the Queue worker to listen to the Queue, however, Laravel's Jobs are self handling. So when the worker on the Logging server retrieves the message from SQS, it will look for a job at the same namespace (with the same Class name) to handle it. Is there any way to handle this differently, or do I just simply need to name the Job Handler on the Logging server, the same as the Job Dispatcher on the Production server.

推荐答案

您可以为每个特定服务器创建不同的队列,并根据必须执行的位置在其中一个服务器上发送每个作业.

You can create different queues for each specific server and send each Job on one of them depending on where they have to be executed.

基本上,这是在特定队列上推送作业的方法:

Basically, this is how to push a job on a specific queue:

$job = (new SendReminderEmail($user))->onQueue('emails');

这是处理来自特定队列的作业的命令:

And here is the command to process jobs from a specific queue:

php artisan queue:listen --queue=emails

希望能帮到你

这篇关于Laravel - 作业在一台服务器上分派,在另一台服务器上处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆