c# - SQS : Getting Number of message in the SQS Queue

标签 c# amazon-web-services amazon-sqs

我正在使用 Amazon-SQS,我尝试从队列中检索大约数量的属性,但响应为空

我正在使用 C# 以下是代码:

GetQueueAttributesRequest attReq = new GetQueueAttributesRequest();
attReq.QueueUrl = "Link to queue";
GetQueueAttributesResponse response = client.GetQueueAttributes(attReq);
Console.WriteLine("App. messages: "+ response.ApproximateNumberOfMessages);

我从请求中得到空响应,我确信队列中也有消息。

最佳答案

您必须明确指定要从 GetQueueAttributes 返回哪些属性。您没有指定任何内容,因此它没有返回任何内容。

尝试简单地将 ApproximateNumberOfMessages 添加到 GetQueueAttributesRequest 上的 AttributeNames 集合:

GetQueueAttributesRequest attReq = new GetQueueAttributesRequest();
attReq.QueueUrl = "Link to queue";
attReq.AttributeNames.Add("ApproximateNumberOfMessages");
GetQueueAttributesResponse response = client.GetQueueAttributes(attReq);

注意事项:

  • 如果您使用的是旧版本的 AWSSDK,则此属性可能被称为 AttributeName 而没有最后一个 s。看起来这在版本 1.x 和 2.x 之间发生了变化。
  • 完整的属性列表可以在 API documentation 中找到

关于c# - SQS : Getting Number of message in the SQS Queue,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31830694/

相关文章:

python - 使用 Boto3 使用自定义日志记录信息为 get_object 创建一个预签名的 S3 URL?

ruby-on-rails - ruby rails : How can I resolve the "Digest::Digest is deprecated; use Digest" warning when uploading to AWS-S3?

django - 为什么 CeleryCAM 不能与 Amazon SQS 一起使用?

java - 通过SDK为所有Principal添加AWS SQS权限

c# - 如何拆分逗号分隔值

c# - 一次播放多个声音文件

amazon-web-services - AWS ECS Fargate 容器运行状况检查命令

php - 在 Laravel 的 artisan 队列 :listen 中捕获 ProcessTimedOutException

c# - 具有多个 ReactiveCommand IsExecuting 的单个 ObservableAsPropertyHelper

c# - 使用 Lambda 表达式将数据传递给线程