Laravel工作者消耗的NodeJS推送队列 [英] NodeJS push queue, consumed by Laravel worker
问题描述
我正在尝试使用Node App发送到SQS的消息.因此,推送"操作由服务器A上的Node App执行,而侦听"操作由服务器B上的Laravel App执行.
I'm trying to consume messages sent to SQS by a Node App. So the "push" action is performed by Node App on the server A, the "listen" action by Laravel App on server B.
我的问题:我不知道如何格式化要使用php artisan queue:work
使用的有效负载.
My problem: I don't know how to format the payload to be consumed with php artisan queue:work
.
任何人以前都经历过这种情况并找到了解决方案吗?
Has anyone experienced this before and found a solution?
谢谢!
推荐答案
找到了!经过一些测试,我终于想到要从队列中读取消息.
Found it! After some tests I finally menage to read messages from the queue.
基本上,有效负载必须具有负责执行工作的类的 job 属性和具有实际数据的 data 属性.像这样:
Basically, the payload must have a job property with the class responsible for executing the work and a data property with the actual data. Something like:
var payload = {
job: 'App\\Jobs\\MyTestJob@handle',
data: {user: foo, email: bar@example.com}
};
然后,有效负载将被编码为json字符串并发送到SQS.
Then the payload will be encoded to json string and sent to SQS.
在Laravel方面,Job类看起来像这样:
On Laravel side the Job class look like this:
public function handle($job, $data){}
队列处理程序将自动解码并将属性注入payload.job中指定的方法.如果未指定任何方法,Laravel将尝试运行:: fire()方法.
The queue handler will automatically decode and inject the properties on the method specified in the payload.job. If no method is specified Laravel will try to run ::fire() method.
这篇关于Laravel工作者消耗的NodeJS推送队列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!