简体   繁体   English

Amazon SQS在php中发送消息属性

[英]Amazon SQS send message attributes in php

I need to implement sending messages to SQS with attributes. 我需要实现使用属性向SQS发送消息。 The body of the message is uploading fine, but I have problem with attributes. 消息正文上传很好,但我的属性有问题。 Message Attributes require Associative array with Name of the Attribute, Data Type, and Value. 消息属性需要具有属性名称,数据类型和值的关联数组。 I got this kind of error : 我遇到了这种错误:

AWS HTTP error: Client error: 400 InvalidParameterValue (client): The request must contain non-empty message attribute name. AWS HTTP错误:客户端错误:400 InvalidParameterValue(客户端):请求必须包含非空消息属性名称。

the function for sending messages: 发送消息的功能:

public function uploadMessage(DataTransferObjectInterface $dataTransferObject)
{

    $command = $this->client->getCommand(
        'SendMessage',
        [
            'QueueUrl' => $this->queueUrl->value(),
            'MessageBody' => $dataTransferObject->getBody()->value(),
            'MessageAttributes' => $dataTransferObject->getAttributes(),

        ]
    );

    $this->client->execute($command);

}

function getAttributes() returns $attributes array function getAttributes()返回$ attributes数组

& the test where I run the code &我运行代码的测试

   $attributes = [
   'TestName' =>
            [
            'Name'=>'test',
            'DataType' => 'string',
            'Value' => 'string',

        ]
    ];
    $age = array("Peter" => "35", "Ben" => "9", "Joe" => "43");
    $json = json_encode($age);
    $body = Json::get($json);

    $dto = new DataTransferObject($attributes, $body);

    $uploader = new SQSManager($sqsClient, $queueUrl);
    $uploader->uploadMessage($dto);

How does the $attributes array should look like? $ attributes数组应该如何?

A fix for this bug is built into version 3.2.1 and greater. 版本3.2.1及更高版本内置了此错误修复程序

Additionally, your message attributes array doesn't match the format shown in the documentation . 此外,您的消息属性数组与文档中显示的格式不匹配。 Your attributes should look like this: 您的属性应如下所示:

$attributes = [
    '<attribute name>' => [
        'DataType' => 'String',
        'StringValue' => '<attribute value>',
    ],
];

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

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