예제 #1
0
 /// <summary>
 /// Moves the message from the timeout queue to the main queue.
 /// </summary>
 /// <param name="queue">The queue.</param>
 /// <param name="messageId">The message id.</param>
 public void MoveTimeoutToMainQueue(OpenedQueue queue, string messageId)
 {
     using (var timeoutQueue = queue.OpenSubQueue(SubQueue.Timeout, QueueAccessMode.Receive))
     {
         var message = timeoutQueue.ReceiveById(messageId);
         message.AppSpecific = 0;//reset timeout flag
         queue.Send(message);
     }
 }
예제 #2
0
 /// <summary>
 /// Moves the message from the timeout queue to the main queue.
 /// </summary>
 /// <param name="queue">The queue.</param>
 /// <param name="messageId">The message id.</param>
 public void MoveTimeoutToMainQueue(OpenedQueue queue, string messageId)
 {
     using (var timeoutQueue = queue.OpenSubQueue(SubQueue.Timeout, QueueAccessMode.Receive))
     {
         var message = timeoutQueue.ReceiveById(messageId);
         message.AppSpecific = 0;                //reset timeout flag
         queue.Send(message);
     }
 }
예제 #3
0
 /// <summary>
 /// Moves the message from the timeout queue to the main queue.
 /// </summary>
 /// <param name="queue">The queue.</param>
 /// <param name="messageId">The message id.</param>
 public void MoveTimeoutToMainQueue(OpenedQueue queue, string messageId)
 {
     using (var destinationQueue = new MessageQueue(GetTimeoutQueuePath(), QueueAccessMode.Receive))
     {
         destinationQueue.MessageReadPropertyFilter.SetAll();
         var message = destinationQueue.ReceiveById(messageId);
         message.AppSpecific = 0;//reset timeout flag
         queue.Send(message);
     }
 }
예제 #4
0
        private void ProcessMessage(
            Message message,
            OpenedQueue messageQueue,
            TransactionScope tx,
            Func <CurrentMessageInformation, bool> messageRecieved,
            Action <CurrentMessageInformation> beforeMessageTransactionCommit,
            Action <CurrentMessageInformation> beforeMessageTransactionRollback,
            Action <CurrentMessageInformation, Exception> messageCompleted)
        {
            Exception ex = null;

            currentMessageInformation = CreateMessageInformation(messageQueue, message, null, null);
            try
            {
                //deserialization errors do not count for module events
                object[] messages = DeserializeMessages(messageQueue, message, MessageSerializationException);
                try
                {
                    foreach (object msg in messages)
                    {
                        currentMessageInformation = CreateMessageInformation(messageQueue, message, messages, msg);

                        if (TransportUtil.ProcessSingleMessage(currentMessageInformation, messageRecieved) == false)
                        {
                            Discard(currentMessageInformation.Message);
                        }
                    }
                }
                catch (Exception e)
                {
                    ex = e;
                    logger.Error("Failed to process message", e);
                }
            }
            catch (Exception e)
            {
                ex = e;
                logger.Error("Failed to deserialize message", e);
            }
            finally
            {
                Action sendMessageBackToQueue = null;
                if (message != null && (messageQueue.IsTransactional == false || consumeInTransaction == false))
                {
                    sendMessageBackToQueue = () => messageQueue.Send(message);
                }
                var messageHandlingCompletion = new MessageHandlingCompletion(tx, sendMessageBackToQueue, ex, messageCompleted, beforeMessageTransactionCommit, beforeMessageTransactionRollback, logger, MessageProcessingFailure, currentMessageInformation);
                messageHandlingCompletion.HandleMessageCompletion();
                currentMessageInformation = null;
            }
        }
예제 #5
0
		private void AddWorkerToQueue(OpenedQueue queue, ReadyToWork work)
		{
			var persistedWorker = new Message
			{
				Formatter = new XmlMessageFormatter(new[] { typeof(string) }),
				Body = work.Endpoint.ToString(),
				Label = ("Known worker: " + work.Endpoint).EnsureLabelLength()
			};
			logger.InfoFormat("New worker: {0}", work.Endpoint);
			queue.Send(persistedWorker.SetSubQueueToSendTo(SubQueue.Workers));

			SendToQueue(secondaryLoadBalancer, new NewWorkerPersisted
			{
				Endpoint = work.Endpoint
			});
			Raise(SentNewWorkerPersisted);
		}
예제 #6
0
		private void HandleStandardMessage(OpenedQueue queue, Message message)
		{
			var worker = readyForWork.Dequeue();

			if (worker == null) // handle message later
			{
				queue.Send(message);

                continuousDeliveryFailures++;

                if (continuousDeliveryFailures >= 100)
                {
                    System.Threading.Thread.Sleep(1000);
                    continuousDeliveryFailures = 0;
                }
			}
			else
			{
                continuousDeliveryFailures = 0;
				var workerEndpoint = endpointRouter.GetRoutedEndpoint(worker);
				using (var workerQueue = MsmqUtil.GetQueuePath(workerEndpoint).Open(QueueAccessMode.Send))
				{
					logger.DebugFormat("Dispatching message '{0}' to {1}", message.Id, workerEndpoint.Uri);
					workerQueue.Send(message);
				}
			}
		}
예제 #7
0
		private void PersistEndpoint(OpenedQueue queue, Message message)
		{
			var queueUri = MsmqUtil.GetQueueUri(message.ResponseQueue);
			if (queueUri == null)
				return;
			bool needToPersist = knownEndpoints.Add(queueUri);
			if (needToPersist == false)
				return;

			logger.InfoFormat("Adding new endpoint: {0}", queueUri);
			var persistedEndPoint = new Message
			{
				Formatter = new XmlMessageFormatter(new[] { typeof(string) }),
				Body = queueUri.ToString(),
				Label = ("Known end point: " + queueUri).EnsureLabelLength()
			};
			queue.Send(persistedEndPoint.SetSubQueueToSendTo(SubQueue.Endpoints));

			SendToQueue(secondaryLoadBalancer, new NewEndpointPersisted
			{
				PersistedEndpoint = queueUri
			});
			Raise(SentNewEndpointPersisted);
		}
예제 #8
0
        private void HandleMessageCompletion(
            Message message,
            TransactionScope tx,
            OpenedQueue messageQueue,
            Exception exception,
            Action<CurrentMessageInformation, Exception> messageCompleted)
        {
            if (exception == null)
            {
                try
                {
                    if (tx != null)
                    {
                        tx.Complete();
                        tx.Dispose();
                    }
                    try
                    {
                        if (messageCompleted != null)
                            messageCompleted(currentMessageInformation, exception);
                    }
                    catch (Exception e)
                    {
                        logger.Error("An error occured when raising the MessageCompleted event, the error will NOT affect the message processing", e);
                    }
                    return;
                }
                catch (Exception e)
                {
                    logger.Warn("Failed to complete transaction, moving to error mode", e);
                    exception = e;
                }
            }
            if (message == null)
                return;

            try
            {
                if (messageCompleted != null)
                    messageCompleted(currentMessageInformation, exception);
            }
            catch (Exception e)
            {
                logger.Error("An error occured when raising the MessageCompleted event, the error will NOT affect the message processing", e);
            }

            try
            {
                var copy = MessageProcessingFailure;
                if (copy != null)
                    copy(currentMessageInformation, exception);
            }
            catch (Exception moduleException)
            {
                logger.Error("Module failed to process message failure: " + exception.Message,
                                             moduleException);
            }

            if (messageQueue.IsTransactional == false)// put the item back in the queue
            {
                messageQueue.Send(message);
            }
        }
예제 #9
0
 public void SendToErrorQueue(OpenedQueue queue, Message message)
 {
     queue.Send(message);
 }
예제 #10
0
        private void ProcessMessage(
            Message message,
            OpenedQueue messageQueue,
            TransactionScope tx,
            Func<CurrentMessageInformation, bool> messageRecieved,
            Action<CurrentMessageInformation> beforeMessageTransactionCommit,
            Action<CurrentMessageInformation> beforeMessageTransactionRollback,
            Action<CurrentMessageInformation, Exception> messageCompleted)
        {
            Exception ex = null;
            currentMessageInformation = CreateMessageInformation(messageQueue, message, null, null);
            try
            {
                //deserialization errors do not count for module events
                object[] messages = DeserializeMessages(messageQueue, message, MessageSerializationException);
                try
                {
                    foreach (object msg in messages)
                    {
                        currentMessageInformation = CreateMessageInformation(messageQueue, message, messages, msg);

                        if (TransportUtil.ProcessSingleMessage(currentMessageInformation, messageRecieved) == false)
                            Discard(currentMessageInformation.Message);
                    }
                }
                catch (Exception e)
                {
                    ex = e;
                    logger.Error("Failed to process message", e);
                }
            }
            catch (Exception e)
            {
                ex = e;
                logger.Error("Failed to deserialize message", e);
            }
            finally
            {
                Action sendMessageBackToQueue = null;
                if (message != null && (messageQueue.IsTransactional == false|| consumeInTransaction==false))
                    sendMessageBackToQueue = () => messageQueue.Send(message);
                var messageHandlingCompletion = new MessageHandlingCompletion(tx, sendMessageBackToQueue, ex, messageCompleted, beforeMessageTransactionCommit, beforeMessageTransactionRollback, logger, MessageProcessingFailure, currentMessageInformation);
                messageHandlingCompletion.HandleMessageCompletion();
                currentMessageInformation = null;
            }
        }
예제 #11
0
 /// <summary>
 /// Moves the message from the timeout queue to the main queue.
 /// </summary>
 /// <param name="queue">The queue.</param>
 /// <param name="messageId">The message id.</param>
 public void MoveTimeoutToMainQueue(OpenedQueue queue, string messageId)
 {
     using (var destinationQueue = new MessageQueue(GetTimeoutQueuePath(), QueueAccessMode.Receive))
     {
         destinationQueue.MessageReadPropertyFilter.SetAll();
         var message = destinationQueue.ReceiveById(messageId);
         message.AppSpecific = 0;//reset timeout flag
         queue.Send(message);
     }
 }
예제 #12
0
        private void HandleStandardMessage(OpenedQueue queue, Message message)
        {
            var worker = readyForWork.Dequeue();

            if (worker == null) // handle message later
            {
                queue.Send(message);
            }
            else
            {
                var workerEndpoint = endpointRouter.GetRoutedEndpoint(worker);
                using (var workerQueue = MsmqUtil.GetQueuePath(workerEndpoint).Open(QueueAccessMode.Send))
                {
                    logger.DebugFormat("Dispatching message '{0}' to {1}", message.Id, workerEndpoint.Uri);
                    workerQueue.Send(message);
                }
            }
        }
예제 #13
0
 public void SendToErrorQueue(OpenedQueue queue, Message message)
 {
     queue.Send(message);
 }