我正在使用Laravel在Amazon SQS队列中推送消息。
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Jobs\ImageProcessor;
use Log;
class ImageProcessorController extends Controller
{
public function processImage(Request $request){
Log::info($request->all());
Log::info("Request Cycle with Queues Begins");
dispatch(new ImageProcessor());
Log::info("Request Cycle with Queues Ends");
echo 'image sent to the queue';
}
}
,结果是队列中的消息如下:
{
"Messages": [
{
"Body": "{\"displayName\":\"App\\\\Jobs\\\\ImageProcessor\",\"job\":\"Illuminate\\\\Queue\\\\CallQueuedHandler@call\",\"maxTries\":null,\"timeout\":null,\"timeoutAt\":null,\"data\":{\"commandName\":\"App\\\\Jobs\\\\ImageProcessor\",\"command\":\"O:23:\\\"App\\\\Jobs\\\\ImageProcessor\\\":7:{s:6:\\\"\\u0000*\\u0000job\\\";N;s:10:\\\"connection\\\";N;s:5:\\\"queue\\\";N;s:15:\\\"chainConnection\\\";N;s:10:\\\"chainQueue\\\";N;s:5:\\\"delay\\\";N;s:7:\\\"chained\\\";a:0:{}}\"}}",
"Attributes": {
"ApproximateFirstReceiveTimestamp": "1523631711067",
"SenderId": "AIDAJYZES3ADLCLSKMIP2",
"ApproximateReceiveCount": "1",
"SentTimestamp": "1523631706715"
},
"ReceiptHandle": "AQEBJFyXHZdHrHLYPSK5Im2+vdXbyrrixqRbAcDVGAGzbs8re6cHIpoz57nW2g2UY+CfkcDsK66rG+qFh4O0vfmAqcc2YCWExZ+J4ixuIKoseTSmCA9ZKHxLOzRDySkDliC4Nvp6G32qh8om3oGTp3eNLMx+ooGuUTfrWipzdM6SesI04Z5fq9P8CWkCKy+Xe7146Y1eJkD68HGrj8yGxlinT5Ian57qQY2GVdXIbZFsTGz6vqB/3WVOvAGmy+b/xMsFD0SNchZUJnFVW7aCmrqKimtXAkuSbDQIhpHGMr2w1iscWtFY5JCvhiPaapkjKcAxf0luR3ygHppt/cBtTr13BNUPMXCohyGc3hdB1/XXcAF0uww+fYvWVQ8IIsYrV5lT2gpYPzg8j+7Zy7Iv1GBlGuZl6lC213AI5w93I+GEmQc=",
"MD5OfBody": "3a84984ce57b8d58162017adc4c2b004",
"MessageId": "61e4dfba-6794-48f3-a006-9637c6913553"
}
]
}
正如您所看到的那样,消息和属性是由laravel自动设置的。 问题是:我该如何修改消息?
答案 0 :(得分:2)
$this->dispatch(new ImageProcessor($param1, $param2, ['additional_data' => 'here']));
如果需要将更多数据发送到队列处理程序(在本例中为ImageProcessor),只需将其添加为参数即可。正如你所说,它将自动获得序列化,发送和反序列化。如果我没有弄错的话,如果你通过它,它甚至应该在另一端找回确切的雄辩模型。
但是,除了传递其他数据之外,您无法真正更改提交邮件的结构。问题是,你为什么要?
如果您想一次发送多条消息,那么您将为此编写自己的逻辑。如果您想使用除Laravel之外的任何其他平台使用队列消息,则相同。