Exemple #1
0
        private void q_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
        {
            //Thread.Sleep(new TimeSpan(0,_configuredSleepValueInMinutes,0));
            MessageQueue q = (MessageQueue)sender;

            DataContractsAndProxy.MessageWrapper wrappedMessage = null;

            try
            {
                q.Formatter = new BinaryMessageFormatter();
                //q.Formatter = new XmlMessageFormatter(new Type[] { typeof(String) });
                // Pause the asynchronous receive operation while processing current message.
                System.Messaging.Message msg = q.EndReceive(e.AsyncResult);

                DataContractSerializer serializer = new DataContractSerializer(typeof(MessageWrapper));
                wrappedMessage = (MessageWrapper)serializer.ReadObject(msg.BodyStream);

                bool exists = false;

                int numberOfAttempts = _attemptsManager.Read(wrappedMessage, out exists);

                //don't queue it anymore and remove it from the attempts processing
                if (_attemptsManager.AttemptsExceeded(numberOfAttempts))
                {
                    _attemptsManager.AttemptsExceededMitigation(wrappedMessage);
                    Thread.Sleep(new TimeSpan(0, _attemptsManager.ConfiguredSleepValueInMinutes, 0));
                }
                else
                {
                    //keep trying until the number of attempts is exceeded
                    DotNetNancyAuditErrorMSMQProcessor processor = new DotNetNancyAuditErrorMSMQProcessor(wrappedMessage, _attemptsManager);
                    _tp.QueueWorkItem(new Amib.Threading.WorkItemCallback(processor.ThreadPoolCallback));
                }

                q.BeginReceive(new TimeSpan(0, 0, 15));
            }

            catch (System.Messaging.MessageQueueException ex)
            {
                if (ex.MessageQueueErrorCode == System.Messaging.MessageQueueErrorCode.IOTimeout)
                {
                    q.BeginReceive(new TimeSpan(0, 0, 15));
                }
                else
                {
                    watchQueue("FormatName:" + q.FormatName);
                    q.Dispose();
                }
            }
            catch (Exception ex)
            {
                _log.Debug("Error Receiving Message off of MSMQ", ex);
                _log.Fatal("This may indicate that a client is putting messages on the MSMQ that the" + Assembly.GetExecutingAssembly().GetType().Name + " cannot Handle", ex);
                watchQueue("FormatName:" + q.FormatName);
                q.Dispose();
            }
        }
 public DotNetNancyAuditDbWriterProcessor(DataContractsAndProxy.MessageWrapper Message)
 {
     try
     {
         _message = Message;
     }
     catch (Exception ex)
     {
         _log.Fatal(ex);
     }
 }
        public string SubmitAuditMessageToDBWriterQ(DataContractsAndProxy.MessageWrapper wrappedMessage)
        {
            string returnMessage = "Audit Point Received - Successful";

            string queuePath = ConfigurationManager.AppSettings["dbWriterQueueName"];
            string messageThresholdString = ConfigurationManager.AppSettings["messageQueueThreshold"];
            int    messageThreshold       = Convert.ToInt32((messageThresholdString == null) ? "1000" : messageThresholdString);

            MessageQueue q = null;

            try
            {
                q = new MessageQueue(queuePath);
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Cannot Receive Audit Messages due to MSMQ, Fatal");
            }
            finally
            {
                if (q != null)
                {
                    q.Dispose();
                }
            }

            try
            {
                if (IsMSMQOverThreshold(q, messageThreshold))
                {
                    _log.Fatal("Audit MSMQ Message Threshold Exceeded, Please Check MSMQ " + q.QueueName);
                }
                try
                {
                    int numberOfTries = _attemptsManager.SubmitAttempt(wrappedMessage);
                    WriteMessage(q, wrappedMessage);
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Cannot Write Audit Messages to MSMQ: " + q.QueueName);
                }
            }
            finally
            {
                if (q != null)
                {
                    q.Dispose();
                }
            }

            return(returnMessage);
        }
Exemple #4
0
        private void WriteMessage(MessageQueue q, DataContractsAndProxy.MessageWrapper wrappedMessage)
        {
            bool fatal = false;
            QueueHelper <MessageWrapper> queueHelper = new QueueHelper <MessageWrapper>();
            string result = queueHelper.WriteMessage(q, wrappedMessage, Assembly.GetExecutingAssembly().GetType().Name, out fatal);

            if (fatal)
            {
                _log.Fatal(Assembly.GetExecutingAssembly().GetType().Name);
                _log.Fatal(result);
                throw new ApplicationException(result);
            }
        }
Exemple #5
0
        private void q_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
        {
            //Thread.Sleep(70000);
            MessageQueue q = (MessageQueue)sender;

            DataContractsAndProxy.MessageWrapper wrappedMessage = null;

            try
            {
                q.Formatter = new BinaryMessageFormatter();
                //q.Formatter = new XmlMessageFormatter(new Type[] { typeof(String) });
                // Pause the asynchronous receive operation while processing current message.
                System.Messaging.Message msg = q.EndReceive(e.AsyncResult);

                DataContractSerializer serializer = new DataContractSerializer(typeof(MessageWrapper));
                wrappedMessage = (MessageWrapper)serializer.ReadObject(msg.BodyStream);

                DotNetNancyAuditDbWriterProcessor processor = new DotNetNancyAuditDbWriterProcessor(wrappedMessage);
                _tp.QueueWorkItem(new Amib.Threading.WorkItemCallback(processor.ThreadPoolCallback));

                q.BeginReceive(new TimeSpan(0, 0, 15));
            }
            catch (System.Messaging.MessageQueueException ex)
            {
                if (ex.MessageQueueErrorCode == System.Messaging.MessageQueueErrorCode.IOTimeout)
                {
                    q.BeginReceive(new TimeSpan(0, 0, 15));
                }
                else
                {
                    watchQueue("FormatName:" + q.FormatName);
                    q.Dispose();
                }
            }
            catch (Exception ex)
            {
                _log.Debug("Error Receiving Message off of MSMQ", ex);
                _log.Fatal("This may indicate that a client is putting messages on the MSMQ that the" + Assembly.GetExecutingAssembly().GetType().Name + " cannot Handle", ex);
                watchQueue("FormatName:" + q.FormatName);
                q.Dispose();
            }
        }
 public DotNetNancyAuditErrorMSMQProcessor(DataContractsAndProxy.MessageWrapper Message, AttemptsManagement attemptsManager)
 {
     _message         = Message;
     _attemptsManager = attemptsManager;
 }