//--- 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) )); }
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) )); }
//--- 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(); }
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) )); }
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); } }
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); } }
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); }
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; } }
//--- 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(); }
//--- Constructors --- public QueueEntry(AwsSqsMessage message, string queue) { Message = new Message(message, queue); VisibleTime = DateTime.MinValue; }
//--- Constructors --- public SendResponse(AwsSqsMessage message) { RequestId = message.RequestId; MD5OfMessageBody = message.MD5OfBody; MessageId = message.MessageId; }
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; } }
public Result<AwsSqsSendResponse> Send(string queue, AwsSqsMessage message, Result<AwsSqsSendResponse> result) { throw new NotImplementedException(); }
public Result<AwsSqsResponse> Delete(AwsSqsMessage message, Result<AwsSqsResponse> result) { _log.DebugFormat("deleting {0}", message.MessageId); Deleted.Add(message); return new Result<AwsSqsResponse>().WithReturn(null); }
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; }