Beispiel #1
0
        private static int GetTotalMessages(SqsMessage pQueue)
        {
            AmazonSQSClient           sqs = SqsConfig.Initialize;
            GetQueueAttributesRequest queueAttributesRequest = new GetQueueAttributesRequest(pQueue.QueueUrl, new List <string> {
                "All"
            });
            GetQueueAttributesResult queueAttributesResult = sqs.GetQueueAttributes(queueAttributesRequest);

            if (queueAttributesResult.HttpStatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new ApplicationException("Problems in the endpoint communication!");
            }

            return(queueAttributesResult.ApproximateNumberOfMessages);
        }
Beispiel #2
0
 public void Send(SqsMessage pQueue)
 {
     try
     {
         AmazonSQSClient    sqs           = SqsConfig.Initialize;
         SendMessageRequest requestToSend = new SendMessageRequest
         {
             MessageBody       = pQueue.MessageBody,
             MessageAttributes = pQueue.MessageAttributes,
             QueueUrl          = pQueue.QueueUrl
         };
         sqs.SendMessage(requestToSend);
     }
     catch (Exception oException)
     {
         throw oException;
     }
 }
Beispiel #3
0
        public Message Receive(SqsMessage pQueue, bool pPeek = true)
        {
            try
            {
                AmazonSQSClient       sqs              = SqsConfig.Initialize;
                Message               message          = null;
                ReceiveMessageRequest requestToReceive = new ReceiveMessageRequest(pQueue.QueueUrl);
                requestToReceive.MessageAttributeNames = new List <string> {
                    "All"
                };
                ReceiveMessageResponse response = sqs.ReceiveMessage(requestToReceive);

                if (response.HttpStatusCode != System.Net.HttpStatusCode.OK)
                {
                    throw new ApplicationException("Problems in the endpoint communication!");
                }

                if (response.Messages.Count > 0)
                {
                    message = response.Messages.First();
                }

                if (pPeek == true)
                {
                    sqs.DeleteMessage(new DeleteMessageRequest()
                    {
                        QueueUrl = pQueue.QueueUrl, ReceiptHandle = message.ReceiptHandle
                    });
                }


                return(message);
            }
            catch (Exception oException)
            {
                throw oException;
            }
        }
Beispiel #4
0
        public IList <Message> List(SqsMessage pQueue, bool pPeek = true)
        {
            try
            {
                IList <Message> message      = new List <Message>();
                int             messagetotal = GetTotalMessages(pQueue);
                if (messagetotal == 0)
                {
                    return(null);
                }

                for (int i = 0; i < messagetotal; i++)
                {
                    message.Add(Receive(pQueue, pPeek));
                }


                return(message);
            }
            catch (Exception oException)
            {
                throw oException;
            }
        }