Container for the parameters to the SendMessageBatch operation. Delivers up to ten messages to the specified queue. This is a batch version of SendMessage . For a FIFO queue, multiple messages within a single batch are enqueued in the order they are sent.

The result of sending each message is reported individually in the response. Because the batch request can result in a combination of successful and unsuccessful actions, you should check for batch errors even when the call returns an HTTP status code of 200.

The maximum allowed individual message size and the maximum total payload size (the sum of the individual lengths of all of the batched messages) are both 256 KB (262,144 bytes).

The following list shows the characters (in Unicode) that are allowed in your message, according to the W3C XML specification:

  • #x9

  • #xA

  • #xD

  • #x20 to #xD7FF

  • #xE000 to #xFFFD

  • #x10000 to #x10FFFF

For more information, see RFC1321. If you send any characters that aren't included in this list, your request is rejected.

If you don't specify the DelaySeconds parameter for an entry, Amazon SQS uses the default value for the queue.

Some actions take lists of parameters. These lists are specified using the param.n notation. Values of n are integers starting from 1. For example, a parameter list with two elements looks like this:

&Attribute.1=this

&Attribute.2=that

Inheritance: AmazonSQSRequest
Esempio n. 1
0
        public async Task SendMany <T>(List <Message <T> > messages)
        {
            var request = new AwsModel.SendMessageBatchRequest
            {
                Entries  = messages.Select(m => { return(new AwsModel.SendMessageBatchRequestEntry(m.Id.ToString(), JsonConvert.SerializeObject(m.Body))); }).ToList(),
                QueueUrl = Url
            };

            var response = await Client.AwsClient.SendMessageBatchAsync(request);

            foreach (var success in response.Successful)
            {
                SuccessEvent?.Invoke(true, $"Message Sent Success => Message id : {success.MessageId} - Message MD5 Body: {success.MD5OfMessageBody}");
            }

            foreach (var failed in response.Failed)
            {
                ErrorEvent?.Invoke(false, $"Message Sent Error => Message id : {failed.Id} - Message Body: {failed.Message}");
            }
        }
        public object Execute(ExecutorContext context)
        {
            var cmdletContext = context as CmdletContext;
            // create request
            var request = new Amazon.SQS.Model.SendMessageBatchRequest();

            if (cmdletContext.Entry != null)
            {
                request.Entries = cmdletContext.Entry;
            }
            if (cmdletContext.QueueUrl != null)
            {
                request.QueueUrl = cmdletContext.QueueUrl;
            }

            CmdletOutput output;

            // issue call
            var client = Client ?? CreateClient(_CurrentCredentials, _RegionEndpoint);

            try
            {
                var    response       = CallAWSServiceOperation(client, request);
                object pipelineOutput = null;
                pipelineOutput = cmdletContext.Select(response, this);
                output         = new CmdletOutput
                {
                    PipelineOutput  = pipelineOutput,
                    ServiceResponse = response
                };
            }
            catch (Exception e)
            {
                output = new CmdletOutput {
                    ErrorResponse = e
                };
            }

            return(output);
        }
        public int SendMessages(string queueUrl = null, int count = 1)
        {
            if (queueUrl == null)
            {
                queueUrl = defaultQueueUrl;
            }

            if (count <= 1)
            {
                var scalarResponse = client.SendMessage(queueUrl, FakeSqsModel.CreateJson());

                return string.IsNullOrEmpty(scalarResponse.MessageId)
                    ? 0
                    : 1;
            }

            var request = new SendMessageBatchRequest
            {
                QueueUrl = queueUrl,
                Entries = new List<SendMessageBatchRequestEntry>(count)
            };

            for (var x = 0; x < count; x++)
            {
                var model = new FakeSqsModel();

                request.Entries.Add(new SendMessageBatchRequestEntry
                {
                    Id = model.Id,
                    MessageBody = model.ToJson(),
                });
            }

            var response = client.SendMessageBatch(request);

            return response.Successful.Count;
        }
        public async Task <SendMessageBatchResponse> SendMessagesAsync(string queueUrl,
                                                                       IEnumerable <SendMessageBatchRequestEntry> messages,
                                                                       CancellationToken cancellationToken = default)
        {
            this.Logger.LogDebug($"[{nameof(this.SendMessagesAsync)}]");

            this.Logger.LogTrace(JsonConvert.SerializeObject(new { queueUrl, messages }));

            if (string.IsNullOrWhiteSpace(queueUrl))
            {
                throw new ArgumentNullException(nameof(queueUrl));
            }
            if (messages == null)
            {
                throw new ArgumentNullException(nameof(messages));
            }
            if (messages.Count() == 0)
            {
                throw new ArgumentException(nameof(messages));
            }

            var request = new Amazon.SQS.Model.SendMessageBatchRequest
            {
                Entries  = messages.ToList(),
                QueueUrl = queueUrl,
            };

            this.Logger.LogTrace(JsonConvert.SerializeObject(value: request));

            var response = await this.Repository.SendMessageBatchAsync(request : request,
                                                                       cancellationToken : cancellationToken == default?this.CancellationToken.Token : cancellationToken);

            this.Logger.LogTrace(JsonConvert.SerializeObject(value: response));

            return(response);
        }
Esempio n. 5
0
 /// <summary>
 /// Initiates the asynchronous execution of the SendMessageBatch operation.
 /// <seealso cref="Amazon.SQS.IAmazonSQS.SendMessageBatch"/>
 /// </summary>
 /// 
 /// <param name="sendMessageBatchRequest">Container for the necessary parameters to execute the SendMessageBatch operation on AmazonSQS.</param>
 /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
 /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 /// 
 /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndSendMessageBatch
 ///         operation.</returns>
 public IAsyncResult BeginSendMessageBatch(SendMessageBatchRequest sendMessageBatchRequest, AsyncCallback callback, object state)
 {
     return invokeSendMessageBatch(sendMessageBatchRequest, callback, state, false);
 }
Esempio n. 6
0
 /// <summary>
 /// <para>This is a batch version of SendMessage. It takes multiple messages and adds each of them to the queue. The result of each add
 /// operation is reported individually in the response.</para>
 /// </summary>
 /// 
 /// <param name="sendMessageBatchRequest">Container for the necessary parameters to execute the SendMessageBatch service method on
 ///          AmazonSQS.</param>
 /// 
 /// <returns>The response from the SendMessageBatch service method, as returned by AmazonSQS.</returns>
 /// 
 /// <exception cref="BatchEntryIdsNotDistinctException"/>
 /// <exception cref="TooManyEntriesInBatchRequestException"/>
 /// <exception cref="BatchRequestTooLongException"/>
 /// <exception cref="InvalidBatchEntryIdException"/>
 /// <exception cref="EmptyBatchRequestException"/>
 public SendMessageBatchResponse SendMessageBatch(SendMessageBatchRequest sendMessageBatchRequest)
 {
     IAsyncResult asyncResult = invokeSendMessageBatch(sendMessageBatchRequest, null, null, true);
     return EndSendMessageBatch(asyncResult);
 }
Esempio n. 7
0
 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();
                     }
                 }
             });
     }
 }
Esempio n. 8
0
        public static void ValidateSendMessageBatch(SendMessageBatchRequest request, SendMessageBatchResponse response)
        {
            if (response != null && response.SendMessageBatchResult != null &&
                response.SendMessageBatchResult.SendMessageBatchResultEntry != null && response.SendMessageBatchResult.SendMessageBatchResultEntry.Count > 0)
            {
                Dictionary<string, string> requestMessages = request.Entries.ToDictionary(entry => entry.Id, entry => entry.MessageBody, StringComparer.Ordinal);

                List<SendMessageBatchResultEntry> resultEntries = response.SendMessageBatchResult.SendMessageBatchResultEntry;
                foreach (SendMessageBatchResultEntry entry in resultEntries)
                {
                    string body = requestMessages[entry.Id];
                    string md5 = entry.MD5OfMessageBody;
                    string id = entry.MessageId;

                    AmazonSQSUtil.ValidateMD5(body, id, md5);
                }
            }
        }
Esempio n. 9
0
    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)
        {
          Console.WriteLine("  For ID '" + fail.Id + "':");
          Console.WriteLine("    Code = " + fail.Code);
          Console.WriteLine("    Message = " + fail.Message);
          Console.WriteLine("    Sender's fault? = " +
            fail.SenderFault);
        }
      }
      #endregion

      Console.ReadLine();
    }
Esempio n. 10
0
		internal SendMessageBatchResponse SendMessageBatch(SendMessageBatchRequest request)
        {
            var task = SendMessageBatchAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                throw e.InnerException;
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Initiates the asynchronous execution of the SendMessageBatch operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the SendMessageBatch operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task<SendMessageBatchResponse> SendMessageBatchAsync(SendMessageBatchRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new SendMessageBatchRequestMarshaller();
            var unmarshaller = SendMessageBatchResponseUnmarshaller.Instance;

            return InvokeAsync<SendMessageBatchRequest,SendMessageBatchResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }
Esempio n. 12
0
        /// <summary>
        /// Delivers up to ten messages to the specified queue.      This is a batch version of
        /// <a>SendMessage</a>.      The result of the send action on each message is reported
        /// individually in the response.      The maximum allowed individual message size is
        /// 256 KB (262,144 bytes).
        /// 
        ///     
        /// <para>
        /// The maximum total payload size (i.e., the sum of all a batch's individual message
        /// lengths)      is also 256 KB (262,144 bytes).
        /// </para>
        ///     
        /// <para>
        /// If the <code>DelaySeconds</code> parameter is not specified for an entry,     the
        /// default for the queue is used.
        /// </para>
        ///     <important>The following list shows the characters (in Unicode) that are allowed
        /// in your message, according      to the W3C XML specification. For more information,
        /// go to <a href="http://www.faqs.org/rfcs/rfc1321.html">http://www.faqs.org/rfcs/rfc1321.html</a>.
        ///       If you send any characters that are not included in the list, your request will
        /// be rejected.      
        /// <para>
        /// #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF]
        /// </para>
        ///     </important>    <important>      Because the batch request can result in a combination
        /// of successful and unsuccessful actions,       you should check for batch errors even
        /// when the call returns an HTTP status code of 200.     </important>    <note>Some API
        /// actions take lists of parameters. These lists are specified using the <code>param.n</code>
        /// notation. Values      of <code>n</code> are integers starting from 1. For example,
        /// a parameter list with two elements looks like this:     </note>    
        /// <para>
        /// <code>&amp;Attribute.1=this</code>
        /// </para>
        ///     
        /// <para>
        /// <code>&amp;Attribute.2=that</code>
        /// </para>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the SendMessageBatch service method.</param>
        /// 
        /// <returns>The response from the SendMessageBatch service method, as returned by SQS.</returns>
        /// <exception cref="BatchEntryIdsNotDistinctException">
        /// Two or more batch entries have the same <code>Id</code> in the request.
        /// </exception>
        /// <exception cref="BatchRequestTooLongException">
        /// The length of all the messages put together is more than the limit.
        /// </exception>
        /// <exception cref="EmptyBatchRequestException">
        /// Batch request does not contain an entry.
        /// </exception>
        /// <exception cref="InvalidBatchEntryIdException">
        /// The <code>Id</code> of a batch entry in a batch request does not abide      by the
        /// specification.
        /// </exception>
        /// <exception cref="TooManyEntriesInBatchRequestException">
        /// Batch request contains more number of entries than permissible.
        /// </exception>
        /// <exception cref="UnsupportedOperationException">
        /// Error code 400. Unsupported operation.
        /// </exception>
        public SendMessageBatchResponse SendMessageBatch(SendMessageBatchRequest request)
        {
            var marshaller = new SendMessageBatchRequestMarshaller();
            var unmarshaller = SendMessageBatchResponseUnmarshaller.Instance;

            return Invoke<SendMessageBatchRequest,SendMessageBatchResponse>(request, marshaller, unmarshaller);
        }
Esempio n. 13
0
 public Task<SendMessageBatchResponse> SendMessageBatchAsync(SendMessageBatchRequest request, CancellationToken cancellationToken = new CancellationToken())
 {
     throw new NotImplementedException();
 }
        /// <exception cref="Exception" />
        internal void SendMessageBatch(List<Message> messages)
        {
            if (messages == null || messages.Count == 0)
                return;

            string url = messages[0].Queue.Url;

            CheckMessageBatchRestrictions(messages, url);

            int batchId = 0;
            var entries = new List<SendMessageBatchRequestEntry>();
            foreach (var message in messages)
            {
                if (string.IsNullOrWhiteSpace(message.BatchId))
                    message.BatchId = Convert.ToString(batchId++);
                entries.Add(new SendMessageBatchRequestEntry
                {
                    DelaySeconds = message.DelaySeconds,
                    Id = message.BatchId,
                    MessageBody = message.Body
                });
            }

            var request = new SendMessageBatchRequest { Entries = entries, QueueUrl = url };
            var response = _sqsClient.SendMessageBatch(request);
            if (response.IsSetSendMessageBatchResult())
            {
                if (response.SendMessageBatchResult.IsSetSendMessageBatchResultEntry())
                {
                    foreach (var resultEntry in response.SendMessageBatchResult.SendMessageBatchResultEntry)
                    {
                        if (resultEntry.IsSetId() && resultEntry.IsSetMessageId())
                        {
                            messages.Single(m => m.BatchId.Equals(resultEntry.Id)).AwsAssignedId = resultEntry.MessageId;
                        }
                    }
                }
                else if (response.SendMessageBatchResult.IsSetBatchResultErrorEntry())
                {
                    foreach (var errorEntry in response.SendMessageBatchResult.BatchResultErrorEntry)
                    {
                        if (errorEntry.IsSetId())
                        {
                            messages.Single(m => m.BatchId.Equals(errorEntry.Id)).Error = new Error
                            {
                                BatchId = errorEntry.Id,
                                Code = errorEntry.Code,
                                MessageText = errorEntry.Message,
                                SenderFault = errorEntry.SenderFault,
                                Service = "SQS Send Message Batch"
                            };
                        }
                    }
                }
            }
        }
Esempio n. 15
0
        public SendMessageBatchResponse SendMessageBatch(SendMessageBatchRequest request)
        {
            if (request.Entries == null || request.Entries.Count <= 0)
            {
                throw new EmptyBatchRequestException("No entires in request");
            }

            if (request.Entries.Count > SqsQueueDefinition.MaxBatchSendItems)
            {
                throw new TooManyEntriesInBatchRequestException("Count of [{0}] exceeds limit of [{1}]".Fmt(request.Entries.Count, SqsQueueDefinition.MaxBatchSendItems));
            }

            var q = GetQueue(request.QueueUrl);

            var response = new SendMessageBatchResponse
            {
                Failed = new List<BatchResultErrorEntry>(),
                Successful = new List<SendMessageBatchResultEntry>()
            };

            var entryIds = new HashSet<string>();

            foreach (var entry in request.Entries)
            {
                string id = null;
                BatchResultErrorEntry batchError = null;

                try
                {
                    if (entryIds.Contains(entry.Id))
                        throw new BatchEntryIdsNotDistinctException("Duplicate Id of [{0}]".Fmt(entry.Id));

                    entryIds.Add(entry.Id);

                    id = q.Send(new SendMessageRequest
                    {
                        MessageBody = entry.MessageBody,
                        QueueUrl = q.QueueDefinition.QueueUrl
                    });
                }
                catch (ReceiptHandleIsInvalidException rhex)
                {
                    batchError = new BatchResultErrorEntry
                    {
                        Id = entry.Id,
                        Message = rhex.Message,
                        Code = rhex.ErrorCode
                    };
                }

                if (id == null)
                {
                    var entryToQueue = batchError ?? new BatchResultErrorEntry
                    {
                        Id = entry.Id,
                        Message = "FakeSendError",
                        Code = "789"
                    };

                    response.Failed.Add(entryToQueue);
                }
                else
                {
                    response.Successful.Add(new SendMessageBatchResultEntry
                    {
                        Id = entry.Id,
                        MessageId = id
                    });
                }
            }

            return response;
        }
Esempio n. 16
0
 /// <summary>
 /// Initiates the asynchronous execution of the SendMessageBatch operation.
 /// </summary>
 /// 
 /// <param name="request">Container for the necessary parameters to execute the SendMessageBatch operation on AmazonSQSClient.</param>
 /// <param name="callback">An Action delegate that is invoked when the operation completes.</param>
 /// <param name="options">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 public void SendMessageBatchAsync(SendMessageBatchRequest request, AmazonServiceCallback<SendMessageBatchRequest, SendMessageBatchResponse> callback, AsyncOptions options = null)
 {
     options = options == null?new AsyncOptions():options;
     var marshaller = new SendMessageBatchRequestMarshaller();
     var unmarshaller = SendMessageBatchResponseUnmarshaller.Instance;
     Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null;
     if(callback !=null )
         callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { 
             AmazonServiceResult<SendMessageBatchRequest,SendMessageBatchResponse> responseObject 
                     = new AmazonServiceResult<SendMessageBatchRequest,SendMessageBatchResponse>((SendMessageBatchRequest)req, (SendMessageBatchResponse)res, ex , ao.State);    
                 callback(responseObject); 
         };
     BeginInvoke<SendMessageBatchRequest>(request, marshaller, unmarshaller, options, callbackHelper);
 }
Esempio n. 17
0
 /// <summary>
 /// Delivers up to ten messages to the specified queue. This is a batch version of <a>SendMessage</a>.
 /// The result of the send action on each message is reported individually in the response.
 /// The maximum allowed individual message size is 256 KB (262,144 bytes).
 /// 
 ///  
 /// <para>
 /// The maximum total payload size (i.e., the sum of all a batch's individual message
 /// lengths) is also 256 KB (262,144 bytes).
 /// </para>
 ///  
 /// <para>
 /// If the <code>DelaySeconds</code> parameter is not specified for an entry, the default
 /// for the queue is used.
 /// </para>
 ///  <important>The following list shows the characters (in Unicode) that are allowed
 /// in your message, according to the W3C XML specification. For more information, go
 /// to <a href="http://www.faqs.org/rfcs/rfc1321.html">http://www.faqs.org/rfcs/rfc1321.html</a>.
 /// If you send any characters that are not included in the list, your request will be
 /// rejected. 
 /// <para>
 /// #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF]
 /// </para>
 ///  </important> <important> Because the batch request can result in a combination of
 /// successful and unsuccessful actions, you should check for batch errors even when the
 /// call returns an HTTP status code of 200. </important> <note>Some API actions take
 /// lists of parameters. These lists are specified using the <code>param.n</code> notation.
 /// Values of <code>n</code> are integers starting from 1. For example, a parameter list
 /// with two elements looks like this: </note> 
 /// <para>
 /// <code>&amp;Attribute.1=this</code>
 /// </para>
 ///  
 /// <para>
 /// <code>&amp;Attribute.2=that</code>
 /// </para>
 /// </summary>
 /// <param name="queueUrl">The URL of the Amazon SQS queue to take action on.</param>
 /// <param name="entries">A list of <a>SendMessageBatchRequestEntry</a> items.</param>
 /// <param name="options">
  ///     A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
  ///     procedure using the AsyncState property.
  /// </param>
 /// 
 /// <returns>The response from the SendMessageBatch service method, as returned by SQS.</returns>
 /// <exception cref="Amazon.SQS.Model.BatchEntryIdsNotDistinctException">
 /// Two or more batch entries have the same <code>Id</code> in the request.
 /// </exception>
 /// <exception cref="Amazon.SQS.Model.BatchRequestTooLongException">
 /// The length of all the messages put together is more than the limit.
 /// </exception>
 /// <exception cref="Amazon.SQS.Model.EmptyBatchRequestException">
 /// Batch request does not contain an entry.
 /// </exception>
 /// <exception cref="Amazon.SQS.Model.InvalidBatchEntryIdException">
 /// The <code>Id</code> of a batch entry in a batch request does not abide by the specification.
 /// </exception>
 /// <exception cref="Amazon.SQS.Model.TooManyEntriesInBatchRequestException">
 /// Batch request contains more number of entries than permissible.
 /// </exception>
 /// <exception cref="Amazon.SQS.Model.UnsupportedOperationException">
 /// Error code 400. Unsupported operation.
 /// </exception>
 public void SendMessageBatchAsync(string queueUrl, List<SendMessageBatchRequestEntry> entries,  AmazonServiceCallback<SendMessageBatchRequest, SendMessageBatchResponse> callback, AsyncOptions options = null)
 {
     var request = new SendMessageBatchRequest();
     request.QueueUrl = queueUrl;
     request.Entries = entries;
     SendMessageBatchAsync(request, callback, options);
 }
Esempio n. 18
0
 IAsyncResult invokeSendMessageBatch(SendMessageBatchRequest sendMessageBatchRequest, AsyncCallback callback, object state, bool synchronized)
 {
     IRequest irequest = new SendMessageBatchRequestMarshaller().Marshall(sendMessageBatchRequest);
     var unmarshaller = SendMessageBatchResponseUnmarshaller.GetInstance();
     AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller);
     Invoke(result);
     return result;
 }
Esempio n. 19
0
        /// <summary>
        /// Initiates the asynchronous execution of the SendMessageBatch operation.
        /// <seealso cref="Amazon.SQS.IAmazonSQS.SendMessageBatch"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the SendMessageBatch operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
		public async Task<SendMessageBatchResponse> SendMessageBatchAsync(SendMessageBatchRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new SendMessageBatchRequestMarshaller();
            var unmarshaller = SendMessageBatchResponseUnmarshaller.GetInstance();
            var response = await Invoke<IRequest, SendMessageBatchRequest, SendMessageBatchResponse>(request, marshaller, unmarshaller, signer, cancellationToken)
                .ConfigureAwait(continueOnCapturedContext: false);
            return response;
        }
Esempio n. 20
0
 /// <summary>
 /// Delivers up to ten messages to the specified queue. This is a batch version of <code>
 /// <a>SendMessage</a> </code>. For a FIFO queue, multiple messages within a single batch
 /// are enqueued in the order they are sent.
 /// 
 ///  
 /// <para>
 /// The result of sending each message is reported individually in the response. Because
 /// the batch request can result in a combination of successful and unsuccessful actions,
 /// you should check for batch errors even when the call returns an HTTP status code of
 /// <code>200</code>.
 /// </para>
 ///  
 /// <para>
 /// The maximum allowed individual message size and the maximum total payload size (the
 /// sum of the individual lengths of all of the batched messages) are both 256 KB (262,144
 /// bytes).
 /// </para>
 ///  <important> 
 /// <para>
 /// The following list shows the characters (in Unicode) that are allowed in your message,
 /// according to the W3C XML specification:
 /// </para>
 ///  <ul> <li> 
 /// <para>
 ///  <code>#x9</code> 
 /// </para>
 ///  </li> <li> 
 /// <para>
 ///  <code>#xA</code> 
 /// </para>
 ///  </li> <li> 
 /// <para>
 ///  <code>#xD</code> 
 /// </para>
 ///  </li> <li> 
 /// <para>
 ///  <code>#x20</code> to <code>#xD7FF</code> 
 /// </para>
 ///  </li> <li> 
 /// <para>
 ///  <code>#xE000</code> to <code>#xFFFD</code> 
 /// </para>
 ///  </li> <li> 
 /// <para>
 ///  <code>#x10000</code> to <code>#x10FFFF</code> 
 /// </para>
 ///  </li> </ul> 
 /// <para>
 /// For more information, see <a href="https://www.ietf.org/rfc/rfc1321.txt">RFC1321</a>.
 /// If you send any characters that aren't included in this list, your request is rejected.
 /// </para>
 ///  </important> 
 /// <para>
 /// If you don't specify the <code>DelaySeconds</code> parameter for an entry, Amazon
 /// SQS uses the default value for the queue.
 /// </para>
 ///  <note> 
 /// <para>
 /// Some actions take lists of parameters. These lists are specified using the <code>param.n</code>
 /// notation. Values of <code>n</code> are integers starting from 1. For example, a parameter
 /// list with two elements looks like this:
 /// </para>
 ///  
 /// <para>
 ///  <code>&amp;Attribute.1=this</code> 
 /// </para>
 ///  
 /// <para>
 ///  <code>&amp;Attribute.2=that</code> 
 /// </para>
 ///  </note>
 /// </summary>
 /// <param name="queueUrl">The URL of the Amazon SQS queue to which batched messages are sent. Queue URLs are case-sensitive.</param>
 /// <param name="entries">A list of <code> <a>SendMessageBatchRequestEntry</a> </code> items.</param>
 /// <param name="cancellationToken">
 ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
 /// </param>
 /// 
 /// <returns>The response from the SendMessageBatch service method, as returned by SQS.</returns>
 /// <exception cref="Amazon.SQS.Model.BatchEntryIdsNotDistinctException">
 /// Two or more batch entries in the request have the same <code>Id</code>.
 /// </exception>
 /// <exception cref="Amazon.SQS.Model.BatchRequestTooLongException">
 /// The length of all the messages put together is more than the limit.
 /// </exception>
 /// <exception cref="Amazon.SQS.Model.EmptyBatchRequestException">
 /// The batch request doesn't contain any entries.
 /// </exception>
 /// <exception cref="Amazon.SQS.Model.InvalidBatchEntryIdException">
 /// The <code>Id</code> of a batch entry in a batch request doesn't abide by the specification.
 /// </exception>
 /// <exception cref="Amazon.SQS.Model.TooManyEntriesInBatchRequestException">
 /// The batch request contains more entries than permissible.
 /// </exception>
 /// <exception cref="Amazon.SQS.Model.UnsupportedOperationException">
 /// Error code 400. Unsupported operation.
 /// </exception>
 public Task<SendMessageBatchResponse> SendMessageBatchAsync(string queueUrl, List<SendMessageBatchRequestEntry> entries, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
 {
     var request = new SendMessageBatchRequest();
     request.QueueUrl = queueUrl;
     request.Entries = entries;
     return SendMessageBatchAsync(request, cancellationToken);
 }
        IAsyncResult invokeSendMessageBatch(SendMessageBatchRequest request, AsyncCallback callback, object state, bool synchronized)
        {
            var marshaller = new SendMessageBatchRequestMarshaller();
            var unmarshaller = SendMessageBatchResponseUnmarshaller.Instance;

            return Invoke(request, callback, state, synchronized, marshaller, unmarshaller, signer);
        }
Esempio n. 22
0
 /// <summary>
 /// Delivers up to ten messages to the specified queue.      This is a batch version of
 /// <a>SendMessage</a>.      The result of the send action on each message is reported
 /// individually in the response.      The maximum allowed individual message size is
 /// 256 KB (262,144 bytes).
 /// 
 ///     
 /// <para>
 /// The maximum total payload size (i.e., the sum of all a batch's individual message
 /// lengths)      is also 256 KB (262,144 bytes).
 /// </para>
 ///     
 /// <para>
 /// If the <code>DelaySeconds</code> parameter is not specified for an entry,     the
 /// default for the queue is used.
 /// </para>
 ///     <important>The following list shows the characters (in Unicode) that are allowed
 /// in your message, according      to the W3C XML specification. For more information,
 /// go to <a href="http://www.faqs.org/rfcs/rfc1321.html">http://www.faqs.org/rfcs/rfc1321.html</a>.
 ///       If you send any characters that are not included in the list, your request will
 /// be rejected.      
 /// <para>
 /// #x9 | #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF]
 /// </para>
 ///     </important>    <important>      Because the batch request can result in a combination
 /// of successful and unsuccessful actions,       you should check for batch errors even
 /// when the call returns an HTTP status code of 200.     </important>    <note>Some API
 /// actions take lists of parameters. These lists are specified using the <code>param.n</code>
 /// notation. Values      of <code>n</code> are integers starting from 1. For example,
 /// a parameter list with two elements looks like this:     </note>    
 /// <para>
 /// <code>&amp;Attribute.1=this</code>
 /// </para>
 ///     
 /// <para>
 /// <code>&amp;Attribute.2=that</code>
 /// </para>
 /// </summary>
 /// <param name="queueUrl">The URL of the Amazon SQS queue to take action on.</param>
 /// <param name="entries">A list of <a>SendMessageBatchRequestEntry</a> items.</param>
 /// 
 /// <returns>The response from the SendMessageBatch service method, as returned by SQS.</returns>
 /// <exception cref="BatchEntryIdsNotDistinctException">
 /// Two or more batch entries have the same <code>Id</code> in the request.
 /// </exception>
 /// <exception cref="BatchRequestTooLongException">
 /// The length of all the messages put together is more than the limit.
 /// </exception>
 /// <exception cref="EmptyBatchRequestException">
 /// Batch request does not contain an entry.
 /// </exception>
 /// <exception cref="InvalidBatchEntryIdException">
 /// The <code>Id</code> of a batch entry in a batch request does not abide      by the
 /// specification.
 /// </exception>
 /// <exception cref="TooManyEntriesInBatchRequestException">
 /// Batch request contains more number of entries than permissible.
 /// </exception>
 /// <exception cref="UnsupportedOperationException">
 /// Error code 400. Unsupported operation.
 /// </exception>
 public SendMessageBatchResponse SendMessageBatch(string queueUrl, List<SendMessageBatchRequestEntry> entries)
 {
     var request = new SendMessageBatchRequest();
     request.QueueUrl = queueUrl;
     request.Entries = entries;
     return SendMessageBatch(request);
 }
 private Amazon.SQS.Model.SendMessageBatchResponse CallAWSServiceOperation(IAmazonSQS client, Amazon.SQS.Model.SendMessageBatchRequest request)
 {
     Utils.Common.WriteVerboseEndpointMessage(this, client.Config, "Amazon Simple Queue Service (SQS)", "SendMessageBatch");
     try
     {
         #if DESKTOP
         return(client.SendMessageBatch(request));
         #elif CORECLR
         return(client.SendMessageBatchAsync(request).GetAwaiter().GetResult());
         #else
                 #error "Unknown build edition"
         #endif
     }
     catch (AmazonServiceException exc)
     {
         var webException = exc.InnerException as System.Net.WebException;
         if (webException != null)
         {
             throw new Exception(Utils.Common.FormatNameResolutionFailureMessage(client.Config, webException.Message), webException);
         }
         throw;
     }
 }
Esempio n. 24
0
        /// <summary>
        /// Initiates the asynchronous execution of the SendMessageBatch operation.
        /// <seealso cref="Amazon.SQS.IAmazonSQS"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the SendMessageBatch operation on AmazonSQSClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        /// 
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndSendMessageBatch
        ///         operation.</returns>
        public IAsyncResult BeginSendMessageBatch(SendMessageBatchRequest request, AsyncCallback callback, object state)
        {
            var marshaller = new SendMessageBatchRequestMarshaller();
            var unmarshaller = SendMessageBatchResponseUnmarshaller.Instance;

            return BeginInvoke<SendMessageBatchRequest>(request, marshaller, unmarshaller,
                callback, state);
        }
        private static void ValidateSendMessageBatch(SendMessageBatchRequest request, SendMessageBatchResponse response)
        {
            if (response != null && response.Successful != null && response.Successful.Count > 0)
            {
                Dictionary<string, SendMessageBatchRequestEntry> requestMessages = request.Entries.ToDictionary(entry => entry.Id, StringComparer.Ordinal);

                List<SendMessageBatchResultEntry> resultEntries = response.Successful;
                foreach (SendMessageBatchResultEntry entry in resultEntries)
                {
                    var message = requestMessages[entry.Id];
                    string id = entry.MessageId;

                    var body = message.MessageBody;
                    var bodyMd5 = entry.MD5OfMessageBody;
                    ValidateMD5(body, id, bodyMd5);

                    var attributes = message.MessageAttributes;
                    var attributesMd5 = entry.MD5OfMessageAttributes;
                    if (attributes != null && attributes.Count > 0 && !string.IsNullOrEmpty(attributesMd5))
                        ValidateMD5(attributes, id, attributesMd5);
                }
            }
        }
Esempio n. 26
0
        /// <summary>
        /// <para>Delivers up to ten messages to the specified queue. This is a batch version of SendMessage. The result of the send action on each
        /// message is reported individually in the response. The maximum allowed individual message size is 256 KB (262,144 bytes).</para> <para>The
        /// maximum total payload size (i.e., the sum of all a batch's individual message lengths) is also 256 KB (262,144 bytes).</para> <para>If the
        /// <c>DelaySeconds</c> parameter is not specified for an entry, the default for the queue is used.</para> <para><b>IMPORTANT:</b>The following
        /// list shows the characters (in Unicode) that are allowed in your message, according to the W3C XML specification. For more information, go to
        /// http://www.faqs.org/rfcs/rfc1321.html. If you send any characters that are not included in the list, your request will be rejected. #x9 |
        /// #xA | #xD | [#x20 to #xD7FF] | [#xE000 to #xFFFD] | [#x10000 to #x10FFFF] </para> <para><b>IMPORTANT:</b> Because the batch request can
        /// result in a combination of successful and unsuccessful actions, you should check for batch errors even when the call returns an HTTP status
        /// code of 200. </para> <para><b>NOTE:</b>Some API actions take lists of parameters. These lists are specified using the param.n notation.
        /// Values of n are integers starting from 1. For example, a parameter list with two elements looks like this: </para> <para>
        /// <c>&amp;amp;Attribute.1=this</c> </para> <para> <c>&amp;amp;Attribute.2=that</c> </para>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the SendMessageBatch service method on
        /// AmazonSQS.</param>
        /// 
        /// <returns>The response from the SendMessageBatch service method, as returned by AmazonSQS.</returns>
        /// 
        /// <exception cref="T:Amazon.SQS.Model.BatchEntryIdsNotDistinctException" />
        /// <exception cref="T:Amazon.SQS.Model.TooManyEntriesInBatchRequestException" />
        /// <exception cref="T:Amazon.SQS.Model.BatchRequestTooLongException" />
        /// <exception cref="T:Amazon.SQS.Model.InvalidBatchEntryIdException" />
        /// <exception cref="T:Amazon.SQS.Model.EmptyBatchRequestException" />
		public SendMessageBatchResponse SendMessageBatch(SendMessageBatchRequest request)
        {
            var task = SendMessageBatchAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return null;
            }
        }
Esempio n. 27
0
        async Task SendOutgoingMessages(ConcurrentQueue<OutgoingMessage> outgoingMessages, ITransactionContext context)
        {
            if (!outgoingMessages.Any()) return;

            var client = GetClientFromTransactionContext(context);

            var messagesByDestination = outgoingMessages
                .GroupBy(m => m.DestinationAddress)
                .ToList();

            await Task.WhenAll(
                messagesByDestination
                    .Select(async batch =>
                    {
                        var entries = batch
                            .Select(message =>
                            {
                                var transportMessage = message.TransportMessage;

                                var headers = transportMessage.Headers;

                                return new SendMessageBatchRequestEntry
                                {
                                    Id = headers[Headers.MessageId],
                                    MessageBody = GetBody(transportMessage.Body),
                                    MessageAttributes = CreateAttributesFromHeaders(headers),
                                    DelaySeconds = GetDelaySeconds(headers)
                                };
                            })
                            .ToList();

                        var destinationUrl = GetDestinationQueueUrlByName(batch.Key, context);

                        var request = new SendMessageBatchRequest(destinationUrl, entries);

                        var response = await client.SendMessageBatchAsync(request);

                        if (response.Failed.Any())
                        {
                            var failed = response.Failed.Select(f => new AmazonSQSException($"Failed {f.Message} with Id={f.Id}, Code={f.Code}, SenderFault={f.SenderFault}"));

                            throw new AggregateException(failed);
                        }
                    })

                );
        }
Esempio n. 28
0
        /// <summary>
        /// <para>This is a batch version of SendMessage. It takes multiple messages and adds each of them to the queue. The result of each add
        /// operation is reported individually in the response.</para>
        /// </summary>
        /// 
        /// <param name="sendMessageBatchRequest">Container for the necessary parameters to execute the SendMessageBatch service method on
        /// AmazonSQS.</param>
        /// 
        /// <returns>The response from the SendMessageBatch service method, as returned by AmazonSQS.</returns>
        /// 
        /// <exception cref="T:Amazon.SQS.Model.BatchEntryIdsNotDistinctException" />
        /// <exception cref="T:Amazon.SQS.Model.TooManyEntriesInBatchRequestException" />
        /// <exception cref="T:Amazon.SQS.Model.BatchRequestTooLongException" />
        /// <exception cref="T:Amazon.SQS.Model.InvalidBatchEntryIdException" />
        /// <exception cref="T:Amazon.SQS.Model.EmptyBatchRequestException" />
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
		public Task<SendMessageBatchResponse> SendMessageBatchAsync(SendMessageBatchRequest sendMessageBatchRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new SendMessageBatchRequestMarshaller();
            var unmarshaller = SendMessageBatchResponseUnmarshaller.GetInstance();
            return Invoke<IRequest, SendMessageBatchRequest, SendMessageBatchResponse>(sendMessageBatchRequest, marshaller, unmarshaller, signer, cancellationToken);
        }
Esempio n. 29
0
        /// <summary>
        /// Enqueues multiple messages into the opened queue at the same time
        /// </summary>
        public bool EnqueueMessages(IList<string> messages)
        {
            ClearErrorInfo ();

            bool result = false;
            try
            {
                var request = new SendMessageBatchRequest
                {
                    QueueUrl = queueurl.QueueUrl
                };
                List<SendMessageBatchRequestEntry> entries = new List<SendMessageBatchRequestEntry> ();

                // Messages counter
                int ix  = 0;

                // Iterating until theres no message left
                while (ix < messages.Count)
                {
                    entries.Clear ();

                    // Storing upper limit of iteration
                    var len = Math.Min (ix + 10, messages.Count);

                    // Iterating over 10
                    for (var i = ix; i < len; i++)
                    {
                        entries.Add (new SendMessageBatchRequestEntry (i.ToString (), messages[i]));
                        ix++;
                    }

                    // Renewing entries from the object
                    request.Entries = entries;

                    // Batch Sending
                    var response = queue.SendMessageBatch (request);

                    // If any message failed to enqueue, use individual enqueue method
                    if (response.Failed != null && response.Failed.Count > 0)
                    {
                        // Hiccup
                        Thread.Sleep (100);

                        foreach (var failedMessage in response.Failed)
                        {
                            // Individual Enqueues
                            EnqueueMessage (failedMessage.Message);
                        }
                    }

                }

                result = true;
            }
            catch (Exception ex)
            {
                ErrorCode    = e_Exception;
                ErrorMessage = ex.Message;
            }

            return result;
        }