public IMessage GetNext() { var message = this.Repository.Get(); var batch = new Batch(); WebHeaderCollection headers = null; var count = 0; long size = 0; long maxMessagesCount = this.BatchConfiguration.BatchMessageCount; long maxBatchSize = this.BatchConfiguration.BatchMessagesSize; while (message != null && count < maxMessagesCount && size < maxBatchSize) { headers = message.Headers; batch.Add(message); size = this.GetSize(batch); count++; message = this.Repository.GetNextMessageAfter(message.Id); } if (size > maxBatchSize) { batch.RemoveLastMessage(); } if (batch.Events.Count > 0) { var lastMessage = batch.Events[batch.Events.Count - 1]; var batchMessage = new Message(this.GetBatchUploadUrl(lastMessage.Url), batch.ToJson()); batchMessage.Id = lastMessage.ReynaId; for (int index = 0; index < headers.Count; index++) { batchMessage.Headers.Add(headers.Keys[index], headers[index]); } return batchMessage; } return null; }
public IMessage GetNext() { var message = this.Repository.Get(); var batch = new Batch(); WebHeaderCollection headers = null; var count = 0; long size = 0; long maxMessagesCount = this.BatchConfiguration.BatchMessageCount; long maxBatchSize = this.BatchConfiguration.BatchMessagesSize; while (message != null && count < maxMessagesCount && size < maxBatchSize) { headers = message.Headers; batch.Add(message); size = this.GetSize(batch); count++; message = this.Repository.GetNextMessageAfter(message.Id); } if (size > maxBatchSize) { batch.RemoveLastMessage(); } if (batch.Events.Count > 0) { var lastMessage = batch.Events[batch.Events.Count - 1]; var batchMessage = new Message(this.GetBatchUploadUrl(lastMessage.Url), batch.ToJson()); batchMessage.Id = lastMessage.ReynaId; for (int index = 0; index < headers.Count; index++) { batchMessage.Headers.Add(headers.Keys[index], headers[index]); } return(batchMessage); } return(null); }
private long GetSize(Batch batch) { return(System.Text.Encoding.UTF8.GetByteCount(batch.ToJson())); }
private long GetSize(Batch batch) { return System.Text.Encoding.UTF8.GetByteCount(batch.ToJson()); }