简体   繁体   English

由Laravel worker消耗的NodeJS推送队列

[英]NodeJS push queue, consumed by Laravel worker

I'm trying to consume messages sent to SQS by a Node App. 我正在尝试使用Node App发送给SQS的消息。 So the "push" action is performed by Node App on the server A, the "listen" action by Laravel App on server B. 因此,“推送”操作由服务器A上的节点应用程序执行,Laravel App在服务器B上执行“监听”操作。

My problem: I don't know how to format the payload to be consumed with php artisan queue:work . 我的问题:我不知道如何使用php artisan queue:work来格式化有效负载。

Has anyone experienced this before and found a solution? 有没有人以前经历过这个并找到了解决方案?

Thanks! 谢谢!

Found it! 找到了! After some tests I finally menage to read messages from the queue. 经过一些测试后,我终于打算从队列中读取消息。

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}
    };

Then the payload will be encoded to json string and sent to SQS. 然后有效载荷将被编码为json字符串并发送到SQS。

On Laravel side the Job class look like this: 在Laravel方面,Job类看起来像这样:

public function handle($job, $data){}

The queue handler will automatically decode and inject the properties on the method specified in the payload.job. 队列处理程序将自动解码并注入payload.job中指定的方法的属性。 If no method is specified Laravel will try to run ::fire() method. 如果没有指定方法,Laravel将尝试运行:: fire()方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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