简体   繁体   English

aws-sdk-php v3.44无法将消息发送到SQS FIFO队列:缺少MessageGroupId?

[英]aws-sdk-php v3.44 fails to sendMessage to SQS FIFO Queue: MessageGroupId missing?

I am using the Amazon SDK for PHP version 3.44 (released 2017-11-30). 我正在使用Amazon SDK for PHP 3.44版本(2017-11-30发布)。 I can connect to my Amazon SQS account and execute the listQueues(), getQueueUrl(), getQueueAttributes(), and receiveMessage() commands just fine. 我可以连接到我的Amazon SQS帐户并执行listQueues(),getQueueUrl(),getQueueAttributes()和receiveMessage()命令。 However, the sendMessage() command consistently fails with the following message: 但是,sendMessage()命令始终失败,并显示以下消息:

The request must contain the parameter MessageGroupId. 该请求必须包含参数MessageGroupId。

I am most definitely including this parameter. 我绝对可以包括此参数。 It doesn't seem to matter which version of the aws-sdk-php API I use, this message keeps coming back. 我使用哪个版本的aws-sdk-php API似乎无关紧要,此消息不断返回。 Here is my code: 这是我的代码:

$queue = SqsClient::factory([
    'profile'     => $profile,
    'region'      => $region,
    'version'     => '2012-11-05',
    'credentials' => $credentials,
]);
$queue_list = $queue->listQueues(); // ok
$url        = $queue->getQueueUrl(['QueueName'=>$queue_name]); // ok
$received   = $queue->receiveMessage(['QueueUrl'=>$url->get('QueueUrl')]); // ok
$response   = $queue->sendMessage([
    'MessageBody'    => $message,
    'MessageGroupId' => $message_group_id,
    'QueueUrl'       => $url->get('QueueUrl'),
]); // fails with message indicating MessageGroupId is missing

I have spent several hours searching for a working example of sending a message up to an Amazon SQS FIFO queue through the PHP SDK, and am beginning to believe this is not possible. 我花了几个小时寻找通过PHP SDK将消息发送到Amazon SQS FIFO队列的可行示例,并且开始相信这是不可能的。 Has anybody out there been able to get the aws-sdk-php library to work with an SQS FIFO queue? 有没有人能够获得aws-sdk-php库来处理SQS FIFO队列?

The first line is creating an instance of SqsClient, not creating a SQS queue. 第一行是创建SqsClient的实例,而不是创建SQS队列。 You still still need to call $queue->createQueue. 您仍然仍然需要调用$ queue-> createQueue。 See the documentation. 请参阅文档。 For fifo queues, you will need to enable "FifoQueue" to "true", and set up the "ContentBasedDeduplication" when creating the queue. 对于fifo队列,需要在创建队列时将“ FifoQueue”启用为“ true”,并设置“ ContentBasedDeduplication”。 When you send your message, depending on the ContentBasedDeduplication setting of the queue you created, you may or may not also need to send a "MessageDeduplicationId" along with the "MessageGroupId". 发送消息时,根据您创建的队列的ContentBasedDeduplication设置,您可能也可能不需要发送“ MessageDeduplicationId”和“ MessageGroupId”。

From your code, I can't see how you created the Queue. 从您的代码中,我看不到您如何创建队列。

  • Did you enable fifo queues with the property "FifoQueue" => "true" 您是否使用属性“ FifoQueue” =>“ true”启用了fifo队列
  • Did you set "ContentBasedDeduplication" to "true" or "false" ? 您是否将“ ContentBasedDeduplication”设置为“ true”或“ false”?
  • Did you name your queue with the extension ".fifo" ? 您是否用扩展名“ .fifo”命名队列?

I did all of these things, and configured my queue with ContentBasedDeduplication set to "false". 我做了所有这些事情,然后将ContentBasedDeduplication设置为“ false”来配置我的队列。 When I send a message, the only other property that I'm sending that you aren't (along with the MessageGroupId) is MessageDeduplicationId. 当我发送一条消息时,我发送的唯一不是(与MessageGroupId一起)的其他属性是MessageDeduplicationId。 I'm able to send messages to the fifo queue just fine using sdk 3.44. 我可以使用sdk 3.44将消息发送到fifo队列。

It looks like Amazon has quietly resolved whatever bug was blocking my API call. 看起来亚马逊已经悄悄解决了阻止我的API调用的任何错误。 I did not change my queue settings or my code. 我没有更改队列设置或代码。 The same API call that resulted in error messages last week now runs just fine. 上周导致错误消息的同一API调用现在运行良好。

I ran into this problem on 3.3.0 forever. 我永远在3.3.0上遇到这个问题。 In my case, I just needed to upgrade to 3.44.2, then pass in MessageDeduplicationId in addition to MessageGroupId. 就我而言,我只需要升级到3.44.2,然后除了MessageGroupId之外还要传入MessageDeduplicationId。 I would probably double check your SDK version if you run into this issue. 如果您遇到此问题,我可能会仔细检查您的SDK版本。

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

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