internal static SendMessageRequest ToSQSMessage <T>(Guid streamGuid, string streamNamespace, IEnumerable <T> events, Dictionary <string, object> requestContext) { var sqsBatchMessage = new SQSBatchContainer(streamGuid, streamNamespace, events.Cast <object>().ToList(), requestContext); var rawBytes = SerializationManager.SerializeToByteArray(sqsBatchMessage); var payload = new JObject(); payload.Add("payload", JToken.FromObject(rawBytes)); return(new SendMessageRequest { MessageBody = payload.ToString() }); }
internal static SendMessageRequest ToSQSMessage <T>( Serializer <SQSBatchContainer> serializer, StreamId streamId, IEnumerable <T> events, Dictionary <string, object> requestContext) { var sqsBatchMessage = new SQSBatchContainer(streamId, events.Cast <object>().ToList(), requestContext); var rawBytes = serializer.SerializeToArray(sqsBatchMessage); var payload = new JObject { { "payload", JToken.FromObject(rawBytes) } }; return(new SendMessageRequest { MessageBody = payload.ToString() }); }
public async Task QueueMessageBatchAsync <T>(Guid streamGuid, string streamNamespace, IEnumerable <T> events, StreamSequenceToken token, Dictionary <string, object> requestContext) { if (token != null) { throw new ArgumentException("SQSStream stream provider currebtly does not support non-null StreamSequenceToken.", "token"); } var queueId = streamQueueMapper.GetQueueForStream(streamGuid, streamNamespace); SQSStorage queue; if (!Queues.TryGetValue(queueId, out queue)) { var tmpQueue = new SQSStorage(this.loggerFactory, queueId.ToString(), DataConnectionString, this.ServiceId); await tmpQueue.InitQueueAsync(); queue = Queues.GetOrAdd(queueId, tmpQueue); } var msg = SQSBatchContainer.ToSQSMessage(this.serializationManager, streamGuid, streamNamespace, events, requestContext); await queue.AddMessage(msg); }
public async Task <IList <IBatchContainer> > GetQueueMessagesAsync(int maxCount) { try { var queueRef = queue; // store direct ref, in case we are somehow asked to shutdown while we are receiving. if (queueRef == null) { return(new List <IBatchContainer>()); } int count = maxCount < 0 || maxCount == QueueAdapterConstants.UNLIMITED_GET_QUEUE_MSG ? SQSStorage.MAX_NUMBER_OF_MESSAGE_TO_PEAK : Math.Min(maxCount, SQSStorage.MAX_NUMBER_OF_MESSAGE_TO_PEAK); var task = queueRef.GetMessages(count); outstandingTask = task; IEnumerable <SQSMessage> messages = await task; List <IBatchContainer> azureQueueMessages = messages .Select(msg => (IBatchContainer)SQSBatchContainer.FromSQSMessage(this.serializationManager, msg, lastReadMessage++)).ToList(); return(azureQueueMessages); } finally { outstandingTask = null; } }