/// <summary> /// Updates the message queue object to table. /// </summary> /// <param name="updateQueue">The update queue.</param> /// <returns></returns> private async Task <int> UpdateMessageQueueObjectToTable(MessageQueueRequest updateQueue) { var _DataHelper = new DataAccessHelper(Core.Enums.DbObjectNames.z_UpdateStatusInMessageQueueRequests, _connectionString); try { SqlParameter[] parameters = { new SqlParameter("@MessageQueueRequestID", SqlDbType.Int), new SqlParameter("@Status", SqlDbType.Int), new SqlParameter("@PublishedOn", SqlDbType.DateTime), new SqlParameter("@NumberOfRetries", SqlDbType.Int), new SqlParameter("@LastTriedOn", SqlDbType.DateTime), }; parameters[0].Value = updateQueue.MessageQueueRequestID; parameters[1].Value = updateQueue.Status; parameters[2].Value = updateQueue.PublishedOn; parameters[3].Value = updateQueue.NumberOfRetries; parameters[4].Value = updateQueue.LastTriedOn; _DataHelper = new DataAccessHelper(Core.Enums.DbObjectNames.z_UpdateStatusInMessageQueueRequests, parameters, _connectionString); return(await _DataHelper.RunAsync()); } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); Console.WriteLine("Critical error in UpdateMessageQueueObjectToTable. Exception is as follows \n " + ex); return(0); } finally { _DataHelper.Dispose(); } }
/// <summary> /// Pushes the messages from message queue table. /// </summary> /// <returns></returns> public async Task PushMessagesFromMessageQueueTable() { MessageQueueResponse responseData = new MessageQueueResponse(); try { //Get 1 first message from table responseData = await GetMessageFromMessageQueueTable(); if (responseData != null) {//Push message var pushResult = await PublishMessageToQueue(responseData.Source, responseData.MessageBody, null, responseData.SNSTopic, responseData.MessageAttribute); if (pushResult.Trim().ToUpper() == "OK") {//Update the message queue MessageQueueRequest messageQueueRequest = new MessageQueueRequest(); messageQueueRequest.LastTriedOn = DateTime.Now; messageQueueRequest.MessageQueueRequestID = responseData.MessageQueueRequestID; messageQueueRequest.NumberOfRetries = responseData.NumberOfRetries + 1; messageQueueRequest.PublishedOn = DateTime.Now; messageQueueRequest.Status = 1; await UpdateMessageQueueObjectToTable(messageQueueRequest); LogInfo.Information("Ended successfully processing of MessageQueueRequestID = " + responseData.MessageQueueRequestID); } else { MessageQueueRequest messageQueueRequest = new MessageQueueRequest(); messageQueueRequest.LastTriedOn = DateTime.Now; messageQueueRequest.MessageQueueRequestID = responseData.MessageQueueRequestID; messageQueueRequest.NumberOfRetries = responseData.NumberOfRetries + 1; messageQueueRequest.PublishedOn = responseData.PublishedOn; messageQueueRequest.Status = 0; await UpdateMessageQueueObjectToTable(messageQueueRequest); LogInfo.Information("Ended Unsuccessfully processing of MessageQueueRequestID = " + responseData.MessageQueueRequestID); } } } catch (Exception ex) { LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical)); MessageQueueRequest messageQueueRequest = new MessageQueueRequest(); messageQueueRequest.LastTriedOn = DateTime.Now; messageQueueRequest.MessageQueueRequestID = responseData.MessageQueueRequestID; messageQueueRequest.NumberOfRetries = responseData.NumberOfRetries + 1; messageQueueRequest.PublishedOn = responseData.PublishedOn; messageQueueRequest.Status = 0; await UpdateMessageQueueObjectToTable(messageQueueRequest); throw ex; } }