当前位置: 首页>>代码示例>>C#>>正文


C# AmazonSQSClient.SendMessageBatch方法代码示例

本文整理汇总了C#中Amazon.SQS.AmazonSQSClient.SendMessageBatch方法的典型用法代码示例。如果您正苦于以下问题:C# AmazonSQSClient.SendMessageBatch方法的具体用法?C# AmazonSQSClient.SendMessageBatch怎么用?C# AmazonSQSClient.SendMessageBatch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Amazon.SQS.AmazonSQSClient的用法示例。


在下文中一共展示了AmazonSQSClient.SendMessageBatch方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SQSSendMessageBatch

    public static void SQSSendMessageBatch()
    {
      #region SQSSendMessageBatch
      var client = new AmazonSQSClient();

      var entry1 = new SendMessageBatchRequestEntry
      {
        DelaySeconds = 0,
        Id = "Entry1",
        MessageAttributes = new Dictionary<string, MessageAttributeValue>
        {
          {
            "MyNameAttribute", new MessageAttributeValue 
              { DataType = "String", StringValue = "John Doe" }
          },
          {
            "MyAddressAttribute", new MessageAttributeValue 
              { DataType = "String", StringValue = "123 Main St." }
          },
          {
            "MyRegionAttribute", new MessageAttributeValue 
              { DataType = "String", StringValue = "Any Town, United States" }
          }
        },
        MessageBody = "John Doe customer information."
      };

      var entry2 = new SendMessageBatchRequestEntry
      {
        DelaySeconds = 0,
        Id = "Entry2",
        MessageAttributes = new Dictionary<string, MessageAttributeValue>
        {
          {
            "MyNameAttribute", new MessageAttributeValue 
              { DataType = "String", StringValue = "Jane Doe" }
          },
          {
            "MyAddressAttribute", new MessageAttributeValue 
              { DataType = "String", StringValue = "456 Center Road" }
          },
          {
            "MyRegionAttribute", new MessageAttributeValue 
              { DataType = "String", StringValue = "Any City, United States" }
          }
        },
        MessageBody = "Jane Doe customer information."
      };

      var entry3 = new SendMessageBatchRequestEntry
      {
        DelaySeconds = 0,
        Id = "Entry3",
        MessageAttributes = new Dictionary<string, MessageAttributeValue>
        {
          {
            "MyNameAttribute", new MessageAttributeValue 
              { DataType = "String", StringValue = "Richard Doe" }
          },
          {
            "MyAddressAttribute", new MessageAttributeValue 
              { DataType = "String", StringValue = "789 East Blvd." }
          },
          {
            "MyRegionAttribute", new MessageAttributeValue 
              { DataType = "String", StringValue = "Anywhere, United States" }
          }
        },
        MessageBody = "Richard Doe customer information."
      };

      var request = new SendMessageBatchRequest
      {
        Entries = new List<SendMessageBatchRequestEntry>() { entry1, entry2, entry3 },
        QueueUrl = "https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyTestQueue"
      };

      var response = client.SendMessageBatch(request);

      if (response.Successful.Count > 0)
      {
        Console.WriteLine("Successfully sent:");

        foreach (var success in response.Successful)
        {
          Console.WriteLine("  For ID: '" + success.Id + "':");
          Console.WriteLine("    Message ID = " + success.MessageId);
          Console.WriteLine("    MD5 of message attributes = " +
            success.MD5OfMessageAttributes);
          Console.WriteLine("    MD5 of message body = " +
            success.MD5OfMessageBody);
        }
      }

      if (response.Failed.Count > 0)
      {
        Console.WriteLine("Failed to be sent:");

        foreach (var fail in response.Failed)
        {
//.........这里部分代码省略.........
开发者ID:rajdotnet,项目名称:aws-sdk-net,代码行数:101,代码来源:SQSSamples.cs

示例2: QueueMessages

 private static void QueueMessages(int count)
 {
     using (AmazonSQSClient client = new AmazonSQSClient(
         ConfigurationManager.AppSettings["AWSAccessKey"],
         ConfigurationManager.AppSettings["AWSSecretAccessKey"]))
     {
         Parallel.ForEach(Partitioner.Create(0, count), (range) =>
             {
                 SendMessageBatchRequest request = new SendMessageBatchRequest();
                 request.QueueUrl = ConfigurationManager.AppSettings["QueueUrl"];
                 int numberOfMessages = range.Item2 - range.Item1;
                 for (int i = 0; i < numberOfMessages; i++)
                 {
                     request.Entries.Add(new SendMessageBatchRequestEntry() { Id = i.ToString(), MessageBody = i.ToString() });
                     if ((request.Entries.Count == 10) |
                         (i == numberOfMessages - 1))
                     {
                         client.SendMessageBatch(request);
                         request.Entries.Clear();
                     }
                 }
             });
     }
 }
开发者ID:Tirael,项目名称:AWSUtilities,代码行数:24,代码来源:SQSServiceTests.cs


注:本文中的Amazon.SQS.AmazonSQSClient.SendMessageBatch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。