Amazon SQS 在 php 中发送消息属性
Amazon SQS send message attributes in php
我需要使用属性实现向 SQS 发送消息。
邮件正文上传正常,但属性有问题。
消息属性需要具有属性名称、数据类型和值的关联数组。我遇到了这种错误:
AWS HTTP 错误:客户端错误:400 InvalidParameterValue(客户端):请求必须包含非空消息属性名称。
发送消息的函数:
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() returns $属性数组
& 我 运行 代码的测试
$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);
$attributes 数组应该是什么样子的?
A fix for this bug 内置于版本 3.2.1 及更高版本中。
此外,您的消息属性数组与 the documentation 中显示的格式不匹配。您的属性应如下所示:
$attributes = [
'<attribute name>' => [
'DataType' => 'String',
'StringValue' => '<attribute value>',
],
];
我需要使用属性实现向 SQS 发送消息。 邮件正文上传正常,但属性有问题。 消息属性需要具有属性名称、数据类型和值的关联数组。我遇到了这种错误:
AWS HTTP 错误:客户端错误:400 InvalidParameterValue(客户端):请求必须包含非空消息属性名称。
发送消息的函数:
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() returns $属性数组
& 我 运行 代码的测试
$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);
$attributes 数组应该是什么样子的?
A fix for this bug 内置于版本 3.2.1 及更高版本中。
此外,您的消息属性数组与 the documentation 中显示的格式不匹配。您的属性应如下所示:
$attributes = [
'<attribute name>' => [
'DataType' => 'String',
'StringValue' => '<attribute value>',
],
];