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

查看:46
本文介绍了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.

我了解如何设置队列工作者来监听队列,但是,Laravel 的作业是自我处理的.所以当 Logging 服务器上的 worker 从 SQS 检索消息时,它会在相同的命名空间(具有相同的 Class 名称)中寻找作业来处理它.有什么方法可以不同地处理这个问题,还是我只需要在日志服务器上命名作业处理程序,与生产服务器上的作业调度程序相同.

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