简体   繁体   English

Laravel队列与Amazon SQS设置消息

[英]Laravel queue with Amazon SQS set up message

I am using Laravel to push messages in a Amazon SQS queue. 我正在使用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';

  }


}

and the result of this is a message in the queue like this: 结果是在队列中显示一条消息,如下所示:

   {
"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"
    }
]
}

as you can see the messages and attributes are set up automagically by laravel. 如您所见,消息和属性是由laravel自动设置的。 The question is: how can I modify the messages? 问题是:如何修改消息?

$this->dispatch(new ImageProcessor($param1, $param2, ['additional_data' => 'here']));

If you need more data to be sent to the queue handler (ImageProcessor in this case), just add it as parameters. 如果需要将更多数据发送到队列处理程序(在本例中为ImageProcessor),只需将其添加为参数即可。 It's going to get automagically, as you say, get serialized, sent and deserialized. 正如您所说,它将自动进行序列化,发送和反序列化。 If i'm not mistaken, it should even retrieve exact eloquent models at the other end if you pass them. 如果我没记错的话,如果您通过它们,它甚至应该在另一端检索准确的雄辩模型。

However, you can't really change the structure of the submitted message, outside of passing along additional data. 但是,除了传递其他数据之外,您不能真正更改已提交消息的结构。 Question for you is, why would you even want to ? 您的问题是,您为什么还要

If you want to send multiple messages in one go, you're gonna have write your own logic for that. 如果您想一次发送多个消息,则需要编写自己的逻辑。 Same if you want to consume the queue messages with any other platform other than Laravel. 如果您想使用Laravel以外的任何其他平台使用队列消息,则相同。

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

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