예제 #1
0
        public static bool Get_Msg_From_Req_Q(out Amazon.SQS.Model.Message msg, out bool msgFound)
        {
            msgFound = false;
            msg = null;
            try
            {
                ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest();
                receiveMessageRequest.MaxNumberOfMessages = 1;
                receiveMessageRequest.QueueUrl = requests_Q_url;
                ReceiveMessageResponse receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest);
                if (receiveMessageResponse.IsSetReceiveMessageResult())
                {
                    ReceiveMessageResult receiveMessageResult = receiveMessageResponse.ReceiveMessageResult;
                    List<Amazon.SQS.Model.Message> receivedMsges = receiveMessageResponse.ReceiveMessageResult.Message;
                    if (receivedMsges.Count == 0)
                    {
                        return true;
                    }
                    msgFound = true;
                    msg = receivedMsges[0];
                }

            }
            catch (AmazonSQSException ex)
            {
                Console.WriteLine("Caught Exception: " + ex.Message);
                Console.WriteLine("Response Status Code: " + ex.StatusCode);
                Console.WriteLine("Error Code: " + ex.ErrorCode);
                Console.WriteLine("Error Type: " + ex.ErrorType);
                Console.WriteLine("Request ID: " + ex.RequestId);
                Console.WriteLine("XML: " + ex.XML);
                return false;
            }
            return true;
        }
예제 #2
0
        private void ReceiveMessage()
        {
            var receiveMessageRequest = new ReceiveMessageRequest();
            receiveMessageRequest.QueueUrl = _handler.QueueUrl;
            var receiveMessageResponse = _sqsClient.ReceiveMessage(receiveMessageRequest);
            if (receiveMessageResponse.IsSetReceiveMessageResult() && receiveMessageResponse.ReceiveMessageResult.Message.Count > 0)
            {
                Console.WriteLine("Received message");
                var receiveMessageResult = receiveMessageResponse.ReceiveMessageResult;
                foreach (Message message in receiveMessageResult.Message)
                {
                    Console.WriteLine("Message body: {0}", message.Body);
                    foreach (var handler in Container.GetAll<IServiceHandler>())
                    {
                        //TODO - need to refactor this, multiple handlers means multiple deserialization
                        if (handler.QueueName == _handler.QueueName && handler.IsRequestHandled(message))
                        {
                            Console.WriteLine("Passing request to handler: {0}", handler.GetType().Name);
                            handler.HandleRequest(message);
                        }
                    }
                }

                Console.WriteLine("Deleting message");
                var messageRecieptHandle = receiveMessageResponse.ReceiveMessageResult.Message[0].ReceiptHandle;
                var deleteRequest = new DeleteMessageRequest()
                                            .WithQueueUrl(_handler.QueueUrl)
                                            .WithReceiptHandle(messageRecieptHandle);
                _sqsClient.DeleteMessage(deleteRequest);
            }
        }
예제 #3
0
        public async Task<Amazon.SQS.Model.Message> GetMessage(string queueName, int  timeoutInMilliseconds, int numberOfCacheableMessages)
        {
            Amazon.SQS.Model.Message message = null;
            if (_queue.ContainsKey(queueName) && _queue[queueName].TryDequeue(out message)) return message;
            
            var request = new ReceiveMessageRequest(queueName)
            {
                MaxNumberOfMessages = numberOfCacheableMessages,
                WaitTimeSeconds = (int)TimeSpan.FromMilliseconds(timeoutInMilliseconds).TotalSeconds
            };

            using (var client = new AmazonSQSClient(_credentials))
            {
                var response = await client.ReceiveMessageAsync(request);
                                
                if (response.HttpStatusCode != HttpStatusCode.OK) return message;

                if (response.ContentLength == 0) return message;

                if (!response.Messages.Any()) return message;

                AddToQueue(queueName, response.Messages);

                if(_queue.ContainsKey(queueName))
                    _queue[queueName].TryDequeue(out message);
            }

            return message;
        }
예제 #4
0
        /// <summary>
        /// Poll messages from the queue.  Given the download process takes many hours there is extra
        /// long retry logic.
        /// </summary>
        /// <returns>The next message in the queue;</returns>
        Message readNextMessage()
        {
            int retryAttempts = 0;
            var receiveRequest = new ReceiveMessageRequest() { QueueUrl = this.queueUrl, MaxNumberOfMessages = 1 };
            while (true)
            {
                try
                {
                    var receiveResponse = this.sqsClient.ReceiveMessage(receiveRequest);
                    retryAttempts = 0;

                    if (receiveResponse.Messages.Count == 0)
                    {
                        Thread.Sleep((int)(this.options.PollingInterval * 1000 * 60));
                        continue;
                    }

                    return receiveResponse.Messages[0];
                }
                catch (Exception)
                {
                    retryAttempts++;
                    if (retryAttempts <= MAX_OPERATION_RETRY)
                        Thread.Sleep(60 * 1000);
                    else
                        throw;
                }
            }
        }
예제 #5
0
        /// <summary>
        /// Poll messages from the queue.  Given the download process takes many hours there is extra
        /// long retry logic.
        /// </summary>
        /// <returns>The next message in the queue;</returns>
        async Task<Message> readNextMessageAsync()
        {
            int retryAttempts = 0;
            var receiveRequest = new ReceiveMessageRequest() { QueueUrl = this.queueUrl, MaxNumberOfMessages = 1 };
            while (true)
            {
                try
                {
                    var receiveResponse = await this.sqsClient.ReceiveMessageAsync(receiveRequest).ConfigureAwait(false);
                    retryAttempts = 0;

                    if (receiveResponse.Messages.Count == 0)
                    {
                        await Task.Delay((int)(this.options.PollingInterval * 1000 * 60)).ConfigureAwait(false);
                        continue;
                    }

                    return receiveResponse.Messages[0];
                }
                catch (Exception)
                {
                    retryAttempts++;
                    if (retryAttempts <= MAX_OPERATION_RETRY)
                        Task.Delay(1000 * 60).Wait();
                    else
                        throw;
                }
            }
        }
예제 #6
0
      public IMessage Next(int timeout)
      {
         try
         {
            var request = new ReceiveMessageRequest()
            {
               MaxNumberOfMessages = 1,
               QueueName = Name,
               VisibilityTimeout = timeout
            };

            var response = _client.ReceiveMessage(request);

            var message = response.ReceiveMessageResult.Message.SingleOrDefault();

            if (message == null)
               return null;

            return new AmazonMessage { Content = message.Body, Message = message };
         }
         catch (AmazonSQSException e)
         {
            throw new MessageQueueException(string.Format("Failed to get next message for '{0}'.", Name), e);
         }
      }
        public AlertMessage GetNextMessage()
        {
            //Receiving a message
            ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest();
            receiveMessageRequest.QueueUrl = queueUrl;
            ReceiveMessageResponse receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest);
            if (receiveMessageResponse.IsSetReceiveMessageResult())
            {
                Console.WriteLine("Printing received message.\n");
                ReceiveMessageResult receiveMessageResult = receiveMessageResponse.ReceiveMessageResult;
                foreach (Message message in receiveMessageResult.Message)
                {
                    AlertMessage m = new AlertMessage();
                    Console.WriteLine("  Message");
                    if (message.IsSetMessageId())
                    {
                        Console.WriteLine("    MessageId: {0}", message.MessageId);
                    }
                    if (message.IsSetReceiptHandle())
                    {
                        Console.WriteLine("    ReceiptHandle: {0}", message.ReceiptHandle);
                    }
                    if (message.IsSetMD5OfBody())
                    {
                        Console.WriteLine("    MD5OfBody: {0}", message.MD5OfBody);
                    }
                    if (message.IsSetBody())
                    {
                        m.Body = message.Body;
                        Console.WriteLine("    Body: {0}", message.Body);
                    }
                    foreach (Amazon.SQS.Model.Attribute attribute in message.Attribute)
                    {
                        Console.WriteLine("  Attribute");
                        if (attribute.IsSetName() && attribute.Name == "Subject")
                        {
                            if (attribute.IsSetValue())
                            {
                                m.Subject = attribute.Value;
                            }
                        }
                        if (attribute.IsSetValue())
                        {
                            Console.WriteLine("    Value: {0}", attribute.Value);
                        }
                    }

                    // Deleting a message
                    Console.WriteLine("Deleting the message.\n");
                    DeleteMessageRequest deleteRequest = new DeleteMessageRequest();
                    deleteRequest.QueueUrl = queueUrl;
                    deleteRequest.ReceiptHandle = message.ReceiptHandle;
                    sqs.DeleteMessage(deleteRequest);

                    return m;
                }
            }
            return null;
        }
예제 #8
0
 public virtual List<CombinedMarketDataRequest> GetRequests()
 {
     var client = this.GetClient();
     var queueReceiveRequest = new ReceiveMessageRequest
                                   {
                                       MaxNumberOfMessages = 10,
                                   };
     var response = client.ReceiveMessage(queueReceiveRequest);
     return Convert(response);
 }
        public Message Receive(ReceiveMessageRequest request)
        {
            if (request == null)
                return null;

            request.MaxNumberOfMessages = 1;

            var response = SqsClient.ReceiveMessage(request);

            return response == null
                ? null
                : response.Messages.SingleOrDefault();
        }
        static void Main(string[] args)
        {
            // AWS: Get instance public address
            string myId = "localhost";
            try
            {
                myId = Encoding.ASCII.GetString(new WebClient().DownloadData("http://169.254.169.254/latest/meta-data/public-hostname"));
            }
            catch
            {
            }

            // AWS SQS Client
            var sqsClient = new AmazonSQSClient();

            while (true)
            {
                // Get the next message
                ReceiveMessageRequest request = new ReceiveMessageRequest()
                    .WithQueueUrl("https://queue.amazonaws.com/*****/codeCampDemo")
                    .WithMaxNumberOfMessages(1);
                var response = sqsClient.ReceiveMessage(request);

                foreach (var retrievedMessage in response.ReceiveMessageResult.Message)
                {
                    var messageJson = JsonValue.Parse(retrievedMessage.Body);

                    var message = messageJson["message"].ReadAs<string>();

                    Console.WriteLine(message);

                    message = "Echo: " + message;

                    string address = string.Format("http://{0}", messageJson["sender"].ReadAs<string>());
                    var connection = new HubConnection(address);
                    connection.Start().Wait();

                    IHubProxy pongHub = connection.CreateProxy("MvcWebRole1.Hubs.EchoHub");
                    pongHub.Invoke("DoUpdateMessage", message, myId).Wait();

                    //Process the message and then delete the message
                    DeleteMessageRequest deleteRequest = new DeleteMessageRequest()
                        .WithQueueUrl("https://queue.amazonaws.com/******/codeCampDemo")
                        .WithReceiptHandle(retrievedMessage.ReceiptHandle);
                    sqsClient.DeleteMessage(deleteRequest);
                }

                Thread.Sleep(1000);
            }
        }
 /// <summary>
 /// Instantiates the Poller.
 /// </summary>
 /// <param name="props">
 /// A <see cref="MessageGearsProperties"/>
 /// </param>
 /// <param name="listener">
 /// A <see cref="MessageGearsListener"/>
 /// </param>
 /// <param name="myAwsAccountKey">
 /// You AWS Account Key
 /// </param>
 /// <param name="myAwsSecretKey">
 /// Your AWS Secret Key
 /// </param>
 public MessageGearsAwsQueuePoller(MessageGearsAwsProperties props, MessageGearsListener listener)
 {
     this.props = props;
     this.emptyQueueDelayMillis = props.EmptyQueuePollingDelaySecs * 1000;
     this.listener = listener;
     AmazonSQSConfig config = new AmazonSQSConfig().WithMaxErrorRetry(props.SQSMaxErrorRetry);
     this.sqs = AWSClientFactory.CreateAmazonSQSClient (props.MyAWSAccountKey, props.MyAWSSecretKey, config);
     this.receiveMessageRequest = new ReceiveMessageRequest ()
         .WithQueueUrl (props.MyAWSEventQueueUrl)
         .WithMaxNumberOfMessages (props.SQSMaxBatchSize)
         .WithAttributeName("ApproximateReceiveCount")
         .WithVisibilityTimeout(props.SQSVisibilityTimeoutSecs);
     this.deleteMessageRequest = new DeleteMessageRequest().WithQueueUrl(props.MyAWSEventQueueUrl);
 }
예제 #12
0
        static void ReadFromQueue(AWSCredentials credentials)
        {
            AmazonSQSClient client = new AmazonSQSClient(credentials, RegionEndpoint.USEast1);

            string queueUrl = "https://sqs.us-east-1.amazonaws.com/025631894481/aws-talk";

            ReceiveMessageRequest request = new ReceiveMessageRequest(queueUrl);
            request.MaxNumberOfMessages = 1;
            ReceiveMessageResponse response = client.ReceiveMessage(request);

            foreach (var message in response.Messages)
            {
                // Do something with the message
            }
        }
 public static Message Get(string queue_url)
 {
     AmazonSQS sqs = AWSClientFactory.CreateAmazonSQSClient();
     ReceiveMessageRequest r_msgreq = new ReceiveMessageRequest();
     r_msgreq.MaxNumberOfMessages = 1;
     r_msgreq.QueueUrl = queue_url;
     Decimal Vis_Timeout = System.Convert.ToDecimal(ConfigurationManager.AppSettings["SQS_Visibility"]);
     r_msgreq.VisibilityTimeout = Vis_Timeout;
     ReceiveMessageResponse r_msgres = sqs.ReceiveMessage(r_msgreq);
     //ChangeMessageVisibilityRequest chg_message_vis = new ChangeMessageVisibilityRequest();
     //chg_message_vis.QueueUrl = ConfigurationManager.AppSettings["SQSUrl"];
     //chg_message_vis.ReceiptHandle = r_msgres.ResponseMetadata.RequestId
     ReceiveMessageResult r_msgrst = r_msgres.ReceiveMessageResult;
     Message msg = r_msgrst.Message.FirstOrDefault();
     return msg;
 }
예제 #14
0
        private static ReceivedMessage Receive()
        {
            var request = new ReceiveMessageRequest
                {
                    QueueUrl = _awsConfig.QueueUrl,
                    MaxNumberOfMessages = 1
                };
            var response = _client.ReceiveMessage(request);

            if (response.Messages.Count == 0) return null;
            var message = response.Messages[0];
            var json = message.Body;
            return new ReceivedMessage
                {
                    Email = JsonConvert.DeserializeObject<EmailMessage>(json),
                    ReceiptHandle = message.ReceiptHandle
                };
        }
예제 #15
0
        public List<QueueMessage> ListTop10Messages(string queueUrl)
        {
            var req = new ReceiveMessageRequest() {
                MaxNumberOfMessages = 10,
                QueueUrl = queueUrl
            };

            req.AttributeName.Add("SentTimestamp");
            req.AttributeName.Add("ApproximateReceiveCount");
            req.AttributeName.Add("ApproximateFirstReceiveTimestamp");

            var result = new List<QueueMessage>(10);
            var response = client.ReceiveMessage(req);
            if (response.IsSetReceiveMessageResult() && response.ReceiveMessageResult.IsSetMessage()) {
                DateTime epochDate = new DateTime(1970,1,1,0,0,0,DateTimeKind.Utc);
                foreach (Message msg in response.ReceiveMessageResult.Message) {
                    var qm = new QueueMessage() {
                        Body = msg.Body,
                        ReceiptHandle = msg.ReceiptHandle
                    };

                    if (msg.IsSetAttribute()) {
                        foreach (Amazon.SQS.Model.Attribute att in msg.Attribute) {
                            switch (att.Name) {
                                case "SentTimestamp":
                                    qm.Sent = epochDate.AddMilliseconds(double.Parse(att.Value));
                                    break;
                                case "ApproximateReceiveCount":
                                    qm.ApproximateReceiveCount = Int32.Parse(att.Value);
                                    break;
                                case "ApproximateFirstReceiveTimestamp":
                                    qm.FirstReceived = epochDate.AddMilliseconds(double.Parse(att.Value));
                                    break;
                            }
                        }
                    }

                    result.Add(qm);
                }
            }

            return result;
        }
예제 #16
0
    public static void SQSReceiveMessage()
    {
      #region SQSReceiveMessage
      var client = new AmazonSQSClient();

      var request = new ReceiveMessageRequest
      {
        AttributeNames = new List<string>() { "All" },
        MaxNumberOfMessages = 5,
        QueueUrl = "https://sqs.us-east-1.amazonaws.com/80398EXAMPLE/MyTestQueue",
        VisibilityTimeout = (int)TimeSpan.FromMinutes(10).TotalSeconds,
        WaitTimeSeconds = (int)TimeSpan.FromSeconds(5).TotalSeconds
      };

      var response = client.ReceiveMessage(request);

      if (response.Messages.Count > 0)
      {
        foreach (var message in response.Messages)
        {
          Console.WriteLine("For message ID '" + message.MessageId + "':");
          Console.WriteLine("  Body: " + message.Body);
          Console.WriteLine("  Receipt handle: " + message.ReceiptHandle);
          Console.WriteLine("  MD5 of body: " + message.MD5OfBody);
          Console.WriteLine("  MD5 of message attributes: " +
            message.MD5OfMessageAttributes);
          Console.WriteLine("  Attributes:");

          foreach (var attr in message.Attributes)
          {
            Console.WriteLine("    " + attr.Key + ": " + attr.Value);
          }
        }
      }
      else
      {
        Console.WriteLine("No messages received.");
      }
      #endregion

      Console.ReadLine();
    }
예제 #17
0
        private void button2_Click(object sender, EventArgs e)
        {
            ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest();
            receiveMessageRequest.QueueUrl = myQueueUrl;
            ReceiveMessageResponse receiveMessageResponse = sqs.ReceiveMessage(receiveMessageRequest);
            if (receiveMessageResponse.IsSetReceiveMessageResult())
            {
                ReceiveMessageResult receiveMessageResult = receiveMessageResponse.ReceiveMessageResult;
                foreach (Amazon.SQS.Model.Message message in receiveMessageResult.Message)
                {
                    if (message.IsSetBody())
                     MessageBox.Show(message.Body);
                }
            }

            String messageRecieptHandle = receiveMessageResponse.ReceiveMessageResult.Message[0].ReceiptHandle;
            DeleteMessageRequest deleteRequest = new DeleteMessageRequest();
            deleteRequest.QueueUrl = myQueueUrl;
            deleteRequest.ReceiptHandle = messageRecieptHandle;
            sqs.DeleteMessage(deleteRequest);
        }
예제 #18
0
        private void ReceiveMessage()
        {
            var receiveMessageRequest = new ReceiveMessageRequest();
            receiveMessageRequest.QueueUrl = _queueUrl;
            var receiveMessageResponse = _sqsClient.ReceiveMessage(receiveMessageRequest);
            if (receiveMessageResponse.IsSetReceiveMessageResult() && receiveMessageResponse.ReceiveMessageResult.Message.Count > 0)
            {
                Console.WriteLine("Received message at: {0}", DateTime.Now.ToLongTimeString());
                var receiveMessageResult = receiveMessageResponse.ReceiveMessageResult;
                foreach (Message message in receiveMessageResult.Message)
                {
                    Console.WriteLine("Message body: {0}", message.Body);
                }

                var response = receiveMessageResponse.FirstMessageAsResponse<QueryServiceResponse>();
                if (response != null)
                {
                    //fetch the data from the response store:
                    Console.WriteLine("Fetching data at: {0}", DateTime.Now.ToLongTimeString());
                    var responseItems = DataStore.Current.Fetch(response.StoreIdentifier, response.ItemKey);
                    var employees = new List<Employee>(responseItems.Count());
                    foreach (var responseItem in responseItems)
                    {
                        var employee = Serializer.Current.Deserialize(typeof(Employee), responseItem) as Employee;
                        Console.WriteLine("Adding employee - {0}", employee);
                        employees.Add(employee);
                    }
                }

                Console.WriteLine("Deleting message");
                var messageRecieptHandle = receiveMessageResponse.ReceiveMessageResult.Message[0].ReceiptHandle;
                var deleteRequest = new DeleteMessageRequest()
                                            .WithQueueUrl(_queueUrl)
                                            .WithReceiptHandle(messageRecieptHandle);
                _sqsClient.DeleteMessage(deleteRequest);
                Console.WriteLine("Completed at: {0}", DateTime.Now.ToLongTimeString());
            }
        }
예제 #19
0
        public override List<Job> ClaimJobs(string queue, int count)
        {
            List<Job> claimedJobs = new List<Job>();

            try
            {
                ReceiveMessageRequest request = new ReceiveMessageRequest();
                request.MaxNumberOfMessages = count;
                request.QueueUrl = GetQueueUrl(SanitiseQueueName(queue));
                ReceiveMessageResponse response = client.ReceiveMessage(request);

                for (int i = 0; i < response.ReceiveMessageResult.Message.Count; i++)
                {
                    Message message = response.ReceiveMessageResult.Message[i];
                    claimedJobs.Add(new Job(queue, message.MessageId, message.ReceiptHandle, message.Body));
                }
            }
            catch (System.Net.WebException)
            {
            }

            return claimedJobs;
        }
예제 #20
0
        public static string DequeueByQueueUrl(string queueUrl)
        {
            using (var client = new AmazonSQSClient(Settings.AccessKey, Settings.Secret))
            {
                var request = new ReceiveMessageRequest()
                {
                    QueueUrl = queueUrl
                };

                var response = client.ReceiveMessage(request).Messages.First();

                var body = response.Body;

                var deleteRequest = new DeleteMessageRequest
                {
                    QueueUrl = queueUrl,
                    ReceiptHandle = response.ReceiptHandle
                };

                client.DeleteMessage(deleteRequest);

                return body;
            }
        }
예제 #21
0
        /// <summary>
        /// <para>Retrieves one or more messages from the specified queue, including the message body and message ID of each message. Messages returned
        /// by this action stay in the queue until you delete them. However, once a message is returned to a <c>ReceiveMessage</c> request, it is not
        /// returned on subsequent <c>ReceiveMessage</c> requests for the duration of the <c>VisibilityTimeout</c> . If you do not specify a
        /// <c>VisibilityTimeout</c> in the request, the overall visibility timeout for the queue is used for the returned messages.</para> <para>If a
        /// message is available in the queue, the call will return immediately. Otherwise, it will wait up to <c>WaitTimeSeconds</c> for a message to
        /// arrive. If you do not specify <c>WaitTimeSeconds</c> in the request, the queue attribute ReceiveMessageWaitTimeSeconds is used to determine
        /// how long to wait.</para> <para>You could ask for additional information about each message through the attributes. Attributes that can be
        /// requested are <c>[SenderId, ApproximateFirstReceiveTimestamp, ApproximateReceiveCount, SentTimestamp]</c> .</para>
        /// </summary>
        /// 
        /// <param name="receiveMessageRequest">Container for the necessary parameters to execute the ReceiveMessage service method on
        /// AmazonSQS.</param>
        /// 
        /// <returns>The response from the ReceiveMessage service method, as returned by AmazonSQS.</returns>
        /// 
        /// <exception cref="T:Amazon.SQS.Model.OverLimitException" />
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
		public Task<ReceiveMessageResponse> ReceiveMessageAsync(ReceiveMessageRequest receiveMessageRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new ReceiveMessageRequestMarshaller();
            var unmarshaller = ReceiveMessageResponseUnmarshaller.GetInstance();
            return Invoke<IRequest, ReceiveMessageRequest, ReceiveMessageResponse>(receiveMessageRequest, marshaller, unmarshaller, signer, cancellationToken);
        }
예제 #22
0
        /// <summary>
        /// <para> Retrieves one or more messages from the specified queue. Long poll support is enabled by using the <c>WaitTimeSeconds</c> parameter.
        /// For more information, see <a href="http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html">Amazon
        /// SQS Long Poll</a> in the <i>Amazon SQS Developer Guide</i> .
        /// </para> <para> Short poll is the default behavior where a weighted random set of machines is sampled on a <c>ReceiveMessage</c> call.
        /// This means only the messages on the sampled machines are returned. If the number of messages in the queue is small (less than 1000), it is
        /// likely you will get fewer messages than you requested per <c>ReceiveMessage</c> call. If the number of messages in the queue is extremely
        /// small, you might not receive any messages in a particular <c>ReceiveMessage</c> response; in which case you should repeat the request.
        /// </para> <para> For each message returned, the response includes the following: </para>
        /// <ul>
        /// <li> <para> Message body </para> </li>
        /// <li> <para> MD5 digest of the message body. For information about MD5, go to <a href="http://www.faqs.org/rfcs/rfc1321.html">http://www.faqs.org/rfcs/rfc1321.html</a> .
        /// </para> </li>
        /// <li> <para> Message ID you received when you sent the message to the queue. </para> </li>
        /// <li> <para> Receipt handle. </para> </li>
        /// 
        /// </ul>
        /// <para> The receipt handle is the identifier you must provide when deleting the message. For more information, see <a href="http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/ImportantIdentifiers.html">Queue and Message
        /// Identifiers</a> in the <i>Amazon SQS Developer Guide</i> .
        /// </para> <para> You can provide the <c>VisibilityTimeout</c> parameter in your request, which will be applied to the messages that Amazon
        /// SQS returns in the response. If you do not include the parameter, the overall visibility timeout for the queue is used for the returned
        /// messages. For more information, see <a href="http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/AboutVT.html">Visibility Timeout</a> in the <i>Amazon SQS Developer Guide</i> .
        /// </para> <para><b>NOTE:</b> Going forward, new attributes might be added. If you are writing code that calls this action, we recommend
        /// that you structure your code so that it can handle new attributes gracefully. </para>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the ReceiveMessage service method on
        /// AmazonSQS.</param>
        /// 
        /// <returns>The response from the ReceiveMessage service method, as returned by AmazonSQS.</returns>
        /// 
        /// <exception cref="T:Amazon.SQS.Model.OverLimitException" />
		public ReceiveMessageResponse ReceiveMessage(ReceiveMessageRequest request)
        {
            var task = ReceiveMessageAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return null;
            }
        }
예제 #23
0
		internal ReceiveMessageResponse ReceiveMessage(ReceiveMessageRequest request)
        {
            var task = ReceiveMessageAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                throw e.InnerException;
            }
        }
예제 #24
0
 /// <summary>
 /// Retrieves one or more messages, with a maximum limit of 10 messages, from the
 /// specified      queue. Long poll support is enabled by using the <code>WaitTimeSeconds</code>
 /// parameter.       For more information, see       <a href="http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html">Amazon
 /// SQS Long Poll</a> in the <i>Amazon SQS Developer Guide</i>.    
 /// 
 ///     
 /// <para>
 ///       Short poll is the default behavior where a weighted random set of machines is
 /// sampled on a <code>ReceiveMessage</code> call.       This means only the messages
 /// on the sampled machines are returned. If the number of messages in the queue is small
 /// (less than 1000),       it is likely you will get fewer messages than you requested
 /// per <code>ReceiveMessage</code> call.       If the number of messages in the queue
 /// is extremely small, you might not receive any messages in      a particular <code>ReceiveMessage</code>
 /// response; in which case you should repeat the      request.    
 /// </para>
 ///     
 /// <para>
 ///       For each message returned, the response includes the following:    
 /// </para>
 ///     <ul>      <li>        
 /// <para>
 ///           Message body        
 /// </para>
 ///       </li>      <li>        
 /// <para>
 ///           MD5 digest of the message body. For information about MD5, go to       
 ///    <a href="http://www.faqs.org/rfcs/rfc1321.html">http://www.faqs.org/rfcs/rfc1321.html</a>.
 ///        
 /// </para>
 ///       </li>      <li>        
 /// <para>
 ///           Message ID you received when you sent the message to the queue.        
 /// </para>
 ///       </li>      <li>        
 /// <para>
 ///           Receipt handle.        
 /// </para>
 ///       </li>      <li>        
 /// <para>
 ///           Message attributes.        
 /// </para>
 ///       </li>      <li>        
 /// <para>
 ///           MD5 digest of the message attributes.        
 /// </para>
 ///       </li>    </ul>    
 /// <para>
 ///       The receipt handle is the identifier you must provide when deleting the message.
 /// For more      information, see             <a href="http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/ImportantIdentifiers.html">Queue
 ///        and Message Identifiers</a> in the <i>Amazon SQS Developer Guide</i>.    
 /// </para>
 ///     
 /// <para>
 ///       You can provide the <code>VisibilityTimeout</code> parameter in your request,
 /// which      will be applied to the messages that Amazon SQS returns in the response.
 /// If you do not include the      parameter, the overall visibility timeout for the queue
 /// is used for the returned messages. For      more information, see       <a href="http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/AboutVT.html">Visibility
 ///        Timeout</a> in the <i>Amazon SQS Developer Guide</i>.          
 /// </para>
 ///     <note>      
 /// <para>
 ///         Going forward, new attributes might be added. If you are writing code that
 /// calls this action,        we recommend that you structure your code so that it can
 /// handle new attributes gracefully.      
 /// </para>
 ///     </note>
 /// </summary>
 /// <param name="queueUrl">The URL of the Amazon SQS queue to take action on.</param>
 /// 
 /// <returns>The response from the ReceiveMessage service method, as returned by SQS.</returns>
 /// <exception cref="OverLimitException">
 /// The action that you requested would violate a limit. For example,      ReceiveMessage
 /// returns this error if the maximum number of messages      inflight has already been
 /// reached. <a>AddPermission</a> returns this error if      the maximum number of permissions
 /// for the queue has already been reached.
 /// </exception>
 public ReceiveMessageResponse ReceiveMessage(string queueUrl)
 {
     var request = new ReceiveMessageRequest();
     request.QueueUrl = queueUrl;
     return ReceiveMessage(request);
 }
예제 #25
0
        /// <summary>
        /// Initiates the asynchronous execution of the ReceiveMessage operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the ReceiveMessage 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<ReceiveMessageResponse> ReceiveMessageAsync(ReceiveMessageRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new ReceiveMessageRequestMarshaller();
            var unmarshaller = ReceiveMessageResponseUnmarshaller.Instance;

            return InvokeAsync<ReceiveMessageRequest,ReceiveMessageResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }
예제 #26
0
        public void pull_from_sqs_queue()
        {
            GetUserNameAndPassword();
            var sqsClient = Amazon.AWSClientFactory.CreateAmazonSQSClient(_key, _secret);
            var queueUrl =
                sqsClient.ListQueues(new ListQueuesRequest().WithQueueNamePrefix("elliotts-blog")).ListQueuesResult.
                    QueueUrl[0];

            var timeToRunThisTest = new TimeSpan(0, 0, 0, 5);
            var stopAt = DateTime.Now.Add(timeToRunThisTest);
            while(DateTime.Now < stopAt)
            {
                var recieveMessageRequest = new ReceiveMessageRequest().WithQueueUrl(queueUrl);
                var recieveMessageResult = sqsClient.ReceiveMessage(recieveMessageRequest);
                foreach (var message in recieveMessageResult.ReceiveMessageResult.Message)
                {
                    Trace.WriteLine(message.Body);
                }
            }
        }
예제 #27
0
 public virtual List<Message> ReadMessages(AmazonSQSClient sqsClient, string queueUrl)
 {
     // Create the request
     var receiveMessageRequest = new ReceiveMessageRequest
     {
         QueueUrl = queueUrl,
         MaxNumberOfMessages = 10
     };
     // Submit the request and return the response
     ReceiveMessageResponse resp = sqsClient.ReceiveMessage(receiveMessageRequest);
     return resp.Messages;
 }
예제 #28
0
        /// <summary>
        /// Initiates the asynchronous execution of the ReceiveMessage operation.
        /// <seealso cref="Amazon.SQS.IAmazonSQS.ReceiveMessage"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the ReceiveMessage 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<ReceiveMessageResponse> ReceiveMessageAsync(ReceiveMessageRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new ReceiveMessageRequestMarshaller();
            var unmarshaller = ReceiveMessageResponseUnmarshaller.GetInstance();
            var response = await Invoke<IRequest, ReceiveMessageRequest, ReceiveMessageResponse>(request, marshaller, unmarshaller, signer, cancellationToken)
                .ConfigureAwait(continueOnCapturedContext: false);
            return response;
        }
예제 #29
0
        /// <summary>
        /// Initiates the asynchronous execution of the ReceiveMessage operation.
        /// <seealso cref="Amazon.SQS.IAmazonSQS"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the ReceiveMessage 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 EndReceiveMessage
        ///         operation.</returns>
        public IAsyncResult BeginReceiveMessage(ReceiveMessageRequest request, AsyncCallback callback, object state)
        {
            var marshaller = new ReceiveMessageRequestMarshaller();
            var unmarshaller = ReceiveMessageResponseUnmarshaller.Instance;

            return BeginInvoke<ReceiveMessageRequest>(request, marshaller, unmarshaller,
                callback, state);
        }
예제 #30
0
        /// <summary>
        /// Retrieves one or more messages, with a maximum limit of 10 messages, from the
        /// specified      queue. Long poll support is enabled by using the <code>WaitTimeSeconds</code>
        /// parameter.       For more information, see       <a href="http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-long-polling.html">Amazon
        /// SQS Long Poll</a> in the <i>Amazon SQS Developer Guide</i>.    
        /// 
        ///     
        /// <para>
        ///       Short poll is the default behavior where a weighted random set of machines is
        /// sampled on a <code>ReceiveMessage</code> call.       This means only the messages
        /// on the sampled machines are returned. If the number of messages in the queue is small
        /// (less than 1000),       it is likely you will get fewer messages than you requested
        /// per <code>ReceiveMessage</code> call.       If the number of messages in the queue
        /// is extremely small, you might not receive any messages in      a particular <code>ReceiveMessage</code>
        /// response; in which case you should repeat the      request.    
        /// </para>
        ///     
        /// <para>
        ///       For each message returned, the response includes the following:    
        /// </para>
        ///     <ul>      <li>        
        /// <para>
        ///           Message body        
        /// </para>
        ///       </li>      <li>        
        /// <para>
        ///           MD5 digest of the message body. For information about MD5, go to       
        ///    <a href="http://www.faqs.org/rfcs/rfc1321.html">http://www.faqs.org/rfcs/rfc1321.html</a>.
        ///        
        /// </para>
        ///       </li>      <li>        
        /// <para>
        ///           Message ID you received when you sent the message to the queue.        
        /// </para>
        ///       </li>      <li>        
        /// <para>
        ///           Receipt handle.        
        /// </para>
        ///       </li>      <li>        
        /// <para>
        ///           Message attributes.        
        /// </para>
        ///       </li>      <li>        
        /// <para>
        ///           MD5 digest of the message attributes.        
        /// </para>
        ///       </li>    </ul>    
        /// <para>
        ///       The receipt handle is the identifier you must provide when deleting the message.
        /// For more      information, see             <a href="http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/ImportantIdentifiers.html">Queue
        ///        and Message Identifiers</a> in the <i>Amazon SQS Developer Guide</i>.    
        /// </para>
        ///     
        /// <para>
        ///       You can provide the <code>VisibilityTimeout</code> parameter in your request,
        /// which      will be applied to the messages that Amazon SQS returns in the response.
        /// If you do not include the      parameter, the overall visibility timeout for the queue
        /// is used for the returned messages. For      more information, see       <a href="http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/AboutVT.html">Visibility
        ///        Timeout</a> in the <i>Amazon SQS Developer Guide</i>.          
        /// </para>
        ///     <note>      
        /// <para>
        ///         Going forward, new attributes might be added. If you are writing code that
        /// calls this action,        we recommend that you structure your code so that it can
        /// handle new attributes gracefully.      
        /// </para>
        ///     </note>
        /// </summary>
        /// <param name="request">Container for the necessary parameters to execute the ReceiveMessage service method.</param>
        /// 
        /// <returns>The response from the ReceiveMessage service method, as returned by SQS.</returns>
        /// <exception cref="OverLimitException">
        /// The action that you requested would violate a limit. For example,      ReceiveMessage
        /// returns this error if the maximum number of messages      inflight has already been
        /// reached. <a>AddPermission</a> returns this error if      the maximum number of permissions
        /// for the queue has already been reached.
        /// </exception>
        public ReceiveMessageResponse ReceiveMessage(ReceiveMessageRequest request)
        {
            var marshaller = new ReceiveMessageRequestMarshaller();
            var unmarshaller = ReceiveMessageResponseUnmarshaller.Instance;

            return Invoke<ReceiveMessageRequest,ReceiveMessageResponse>(request, marshaller, unmarshaller);
        }