示例#1
0
        //--- Methods ---
        public Result <AwsSqsSendResponse> Send(string queue, AwsSqsMessage message, Result <AwsSqsSendResponse> result)
        {
            var parameters = new Dictionary <string, string> {
                { "MessageBody", message.Body }
            };

            return(HandleResponse(true, queue, "SendMessage", parameters, result,
                                  m => new AwsSqsSendResponse(m)
                                  ));
        }
示例#2
0
        public Result <AwsSqsResponse> Delete(AwsSqsMessage message, Result <AwsSqsResponse> result)
        {
            var parameters = new Dictionary <string, string> {
                { "ReceiptHandle", message.ReceiptHandle },
            };

            return(HandleResponse(true, message.OriginQueue, "DeleteMessage", parameters, result,
                                  m => new AwsSqsResponse(m)
                                  ));
        }
示例#3
0
 //--- Constructors ---
 public Message(AwsSqsMessage message, string queue)
 {
     foreach (var attr in message.Attributes)
     {
         _attributes.Add(attr);
     }
     this.Body          = message.Body;
     this.MD5OfBody     = StringUtil.ComputeHashString(Body);
     this.MessageId     = Guid.NewGuid().ToString();
     this.OriginQueue   = queue;
     this.ReceiptHandle = Guid.NewGuid().ToString();
 }
示例#4
0
        public Result <IEnumerable <AwsSqsMessage> > Receive(string queue, int maxMessages, TimeSpan visibilityTimeout, Result <IEnumerable <AwsSqsMessage> > result)
        {
            // CLEANUP: punting on attributes right now
            var parameters = new Dictionary <string, string>();

            if (maxMessages != AwsSqsDefaults.DEFAULT_MESSAGES)
            {
                parameters.Add("MaxNumberOfMessages", maxMessages.ToString());
            }
            if (visibilityTimeout != AwsSqsDefaults.DEFAULT_VISIBILITY)
            {
                parameters.Add("VisibilityTimeout", Math.Floor(visibilityTimeout.TotalSeconds).ToString());
            }
            return(HandleResponse(false, queue, "ReceiveMessage", parameters, result,
                                  m => AwsSqsMessage.FromSqsResponse(queue, m)
                                  ));
        }
示例#5
0
 public Result <AwsSqsSendResponse> Send(string queue, AwsSqsMessage message, Result <AwsSqsSendResponse> result)
 {
     try {
         var msgQueue = GetQueue(queue);
         ThrowIfQueueIsNull(msgQueue);
         if (msgQueue == null)
         {
             throw new AwsSqsRequestException("AWS.SimpleQueueService.NonExistentQueue", DreamMessage.InternalError());
         }
         var enqueued = new QueueEntry(message, queue);
         lock (msgQueue) {
             msgQueue.Add(enqueued);
         }
         _messageCounter++;
         result.Return(new SendResponse(enqueued.Message));
         return(result);
     } catch (Exception e) {
         result.Throw(e);
         return(result);
     }
 }
示例#6
0
 public Result <AwsSqsResponse> Delete(AwsSqsMessage message, Result <AwsSqsResponse> result)
 {
     try {
         var queue    = message.OriginQueue;
         var msgQueue = GetQueue(queue);
         if (msgQueue != null)
         {
             lock (msgQueue) {
                 var entry = msgQueue.FirstOrDefault(x => x.Message.ReceiptHandle == message.ReceiptHandle);
                 if (entry != null)
                 {
                     msgQueue.Remove(entry);
                 }
             }
         }
         result.Return(new SendResponse(message));
         return(result);
     } catch (Exception e) {
         result.Throw(e);
         return(result);
     }
 }
示例#7
0
        internal static IEnumerable <AwsSqsMessage> FromSqsResponse(string queue, XDoc doc)
        {
            var messages  = new List <AwsSqsMessage>();
            var requestId = doc["sqs:ResponseMetadata/sqs:RequestId"].AsText;

            foreach (var msgDoc in doc["sqs:ReceiveMessageResult/sqs:Message"])
            {
                var msg = new AwsSqsMessage {
                    MessageId     = msgDoc["sqs:MessageId"].AsText,
                    OriginQueue   = queue,
                    ReceiptHandle = msgDoc["sqs:ReceiptHandle"].AsText,
                    MD5OfBody     = msgDoc["sqs:MD5OfBody"].AsText,
                    Body          = msgDoc["sqs:Body"].AsText,
                    RequestId     = requestId
                };
                foreach (var attr in msgDoc["sqs:Attribute"])
                {
                    msg.Attributes[attr["Name"].AsText] = attr["Value"].AsText;
                }
                messages.Add(msg);
            }
            return(messages);
        }
示例#8
0
 public Result<AwsSqsResponse> Delete(AwsSqsMessage message, Result<AwsSqsResponse> result)
 {
     try {
         var queue = message.OriginQueue;
         var msgQueue = GetQueue(queue);
         if(msgQueue != null) {
             lock(msgQueue) {
                 var entry = msgQueue.FirstOrDefault(x => x.Message.ReceiptHandle == message.ReceiptHandle);
                 if(entry != null) {
                     msgQueue.Remove(entry);
                 }
             }
         }
         result.Return(new SendResponse(message));
         return result;
     } catch(Exception e) {
         result.Throw(e);
         return result;
     }
 }
示例#9
0
 //--- Constructors ---
 public Message(AwsSqsMessage message, string queue)
 {
     foreach(var attr in message.Attributes) {
         _attributes.Add(attr);
     }
     this.Body = message.Body;
     this.MD5OfBody = StringUtil.ComputeHashString(Body);
     this.MessageId = Guid.NewGuid().ToString();
     this.OriginQueue = queue;
     this.ReceiptHandle = Guid.NewGuid().ToString();
 }
示例#10
0
 //--- Constructors ---
 public QueueEntry(AwsSqsMessage message, string queue)
 {
     Message = new Message(message, queue);
     VisibleTime = DateTime.MinValue;
 }
示例#11
0
 //--- Constructors ---
 public QueueEntry(AwsSqsMessage message, string queue)
 {
     Message     = new Message(message, queue);
     VisibleTime = DateTime.MinValue;
 }
示例#12
0
 //--- Constructors ---
 public SendResponse(AwsSqsMessage message)
 {
     RequestId = message.RequestId;
     MD5OfMessageBody = message.MD5OfBody;
     MessageId = message.MessageId;
 }
示例#13
0
 //--- Constructors ---
 public SendResponse(AwsSqsMessage message)
 {
     RequestId        = message.RequestId;
     MD5OfMessageBody = message.MD5OfBody;
     MessageId        = message.MessageId;
 }
示例#14
0
 public Result<AwsSqsSendResponse> Send(string queue, AwsSqsMessage message, Result<AwsSqsSendResponse> result)
 {
     try {
         var msgQueue = GetQueue(queue);
         ThrowIfQueueIsNull(msgQueue);
         if(msgQueue == null) {
             throw new AwsSqsRequestException("AWS.SimpleQueueService.NonExistentQueue", DreamMessage.InternalError());
         }
         var enqueued = new QueueEntry(message, queue);
         lock(msgQueue) {
             msgQueue.Add(enqueued);
         }
         _messageCounter++;
         result.Return(new SendResponse(enqueued.Message));
         return result;
     } catch(Exception e) {
         result.Throw(e);
         return result;
     }
 }
示例#15
0
 public Result<AwsSqsSendResponse> Send(string queue, AwsSqsMessage message, Result<AwsSqsSendResponse> result)
 {
     throw new NotImplementedException();
 }
示例#16
0
 public Result<AwsSqsResponse> Delete(AwsSqsMessage message, Result<AwsSqsResponse> result)
 {
     _log.DebugFormat("deleting {0}", message.MessageId);
     Deleted.Add(message);
     return new Result<AwsSqsResponse>().WithReturn(null);
 }
示例#17
0
 internal static IEnumerable<AwsSqsMessage> FromSqsResponse(string queue, XDoc doc)
 {
     var messages = new List<AwsSqsMessage>();
     var requestId = doc["sqs:ResponseMetadata/sqs:RequestId"].AsText;
     foreach(var msgDoc in doc["sqs:ReceiveMessageResult/sqs:Message"]) {
         var msg = new AwsSqsMessage {
             MessageId = msgDoc["sqs:MessageId"].AsText,
             OriginQueue = queue,
             ReceiptHandle = msgDoc["sqs:ReceiptHandle"].AsText,
             MD5OfBody = msgDoc["sqs:MD5OfBody"].AsText,
             Body = msgDoc["sqs:Body"].AsText,
             RequestId = requestId
         };
         foreach(var attr in msgDoc["sqs:Attribute"]) {
             msg.Attributes[attr["Name"].AsText] = attr["Value"].AsText;
         }
         messages.Add(msg);
     }
     return messages;
 }