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

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

问题描述

我正在研究Laravel应用程序的日志记录方面,amd计划将数据发送到SQS以便以后进行检索.但是,我想将作业从生产服务器分派到AWS Queue,然后让Queue在监听日志的单独的Logging服务器上工作.

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.

我了解如何设置队列工作程序以侦听队列,但是,Laravel的工作是自我处理的.因此,当日志服务器上的工作程序从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.

推荐答案

您可以为每个特定的服务器创建不同的队列,并根据必须在何处执行将每个Job发送到其中的一个.

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天全站免登陆