Beispiel #1
0
        /// <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;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets the message from message queue table.
        /// </summary>
        /// <returns></returns>
        private async Task <MessageQueueResponse> GetMessageFromMessageQueueTable()
        {
            var _DataHelper = new DataAccessHelper(Core.Enums.DbObjectNames.z_GetSingleMessageQueueRecord, _connectionString);

            try
            {
                DataTable dt = new DataTable();
                return(await Task.Run(() =>
                {
                    MessageQueueResponse message = new MessageQueueResponse();

                    _DataHelper.Run(dt);

                    if (dt.Rows.Count > 0)
                    {
                        message = (from model in dt.AsEnumerable()
                                   select new MessageQueueResponse()
                        {
                            MessageQueueRequestID = model.Field <int>("MessageQueueRequestID"),
                            LastTriedOn = model.Field <DateTime>("LastTriedOn"),
                            Status = model.Field <int>("Status"),
                            CreatedOn = model.Field <DateTime>("CreatedOn"),
                            MessageAttribute = model.Field <string>("MessageAttribute"),
                            MessageBody = model.Field <string>("MessageBody"),
                            NumberOfRetries = model.Field <int>("NumberOfRetries"),
                            PublishedOn = model.Field <DateTime>("PublishedOn"),
                            SNSTopic = model.Field <string>("SNSTopic"),
                            Source = model.Field <string>("Source")
                        }).FirstOrDefault();
                        LogInfo.Information("Started processing  MessageQueueRequestID =  " + message.MessageQueueRequestID);

                        return message;
                    }
                    return null;
                }));
            }

            catch (Exception ex)
            {
                LogInfo.Error(new ExceptionHelper().GetLogString(ex, ErrorLevel.Critical));
                Console.WriteLine("Critical error in GetMessageFromMessageQueueTable. Exception is as follows \n " + ex);
                throw;
            }
            finally
            {
                _DataHelper.Dispose();
            }
        }