Amazon SQS sends post attributes to php

I need to implement sending messages in SQS with attributes. The message body is loading fine, but I have a problem with attributes. Message attributes require an associative array with the attribute name, data type, and value. I got an error like this:

AWS HTTP Error: Client Error: 400 InvalidParameterValue (Client): The request must contain a non-empty message attribute name.

message sending function:

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

}

      

GetAttributes () function returns $ attributes array

& 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);

      

What does the $ attributes array look like?

+3


source to share


1 answer


A fix for this bug is built into version 3.2.1 and higher.

Also, your array of message attributes does not follow the format shown in the documentation . Your attributes should look like this:



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

      

+5


source







All Articles