public async Task ShouldReturnNull_IfGetMessagesIsUnsuccessful() { //Arrange var service = SetupService(); _queService.GetMessagesFromQueAsync <RingbaUOW>(Arg.Any <int>(), Arg.Any <int>(), Arg.Any <int>()) .Returns(Task.FromResult(new MessageBatchResult <RingbaUOW> { IsSuccessfull = false, })); //Act var result = await service.FetchMessagesAsync(); //Assert Assert.Equal(null, result); }
public virtual async Task <MessageBatchResult <RingbaUOW> > FetchMessagesAsync() { await LogInfoAsync( $"ImplementMeService.DoWorkAsync is trying to fetch a new message batch @ {Environment.MachineName}", "PreFetchMessageBatch"); var batch = await _queService.GetMessagesFromQueAsync <RingbaUOW>(10, 30, 30); if (!batch.IsSuccessfull) { await LogErrorAsync(batch.ErrorCode, batch.ErrorMessage, "FetchMessageBatch"); return(null); } await LogInfoAsync( $"ImplementMeService.DoWorkAsync fetched {batch.NumberOfMessages} @ {Environment.MachineName}", "FetchMessageBatch"); return(batch); }
public void DoWork() { // Pseudo-code to illustrate a naive implementation. Provide an optimal implementation. while (true) { var batch = _queService.GetMessagesFromQueAsync <RingbaUOW>(10, 30, 30).Result; foreach (var message in batch.Messages) { var result = _processService.ProccessMessageAsync(message.Body).Result; _queService.UpdateMessagesAsync(new UpdateBatchRequest[] { new UpdateBatchRequest { Id = message.Id, MessageCompleted = result.IsSuccessfull } }); } } }
private async Task <MessageBatchResult <RingbaUOW> > GetMessagesBatch() => await _queService.GetMessagesFromQueAsync <RingbaUOW>( MaxNumberOfMessages, EmptyQueWaitTimeInSeconds, MaxMessageProcessTimeInSeconds);