コード例 #1
0
        public override bool HandlePeekedMessage(IMsmqTransport transport, OpenedQueue queue, Message message)
        {
            using (var tx = transactionStrategy.Begin())
            {
                var processMessageAt = DateTime.FromBinary(BitConverter.ToInt64(message.Extension, 16));
                if (CurrentTime >= processMessageAt)
                {
                    return(false);
                }

                string id;
                if (queueStrategy.TryMoveMessage(queue, message, SubQueue.Timeout, out id) == false)
                {
                    logger.DebugFormat("Failed to move message to timeout queue");
                    return(false);
                }
                tx.Complete();

                logger.DebugFormat("Moving message {0} to timeout queue, will be processed at: {1}",
                                   id, processMessageAt);

                timeoutMessageIds.Write(writer => writer.Add(processMessageAt, id));

                return(true);
            }
        }
コード例 #2
0
        protected void PeekMessageOnBackgroundThread(object state)
        {
            using (var queue = Endpoint.InitalizeQueue())
                while (shouldStop == false)
                {
                    try
                    {
                        Message message;
                        bool?   peek = TryPeek(queue, out message);

                        if (peek == false || shouldStop)//error reading from queue
                        {
                            TransportState = TransportState.FailedToReadFromQueue;
                            return;       // return from method, we have failed
                        }
                        if (peek == null) //nothing was found
                        {
                            continue;
                        }

                        if ((MessageType)((message.AppSpecific & 0xFFFF0000) >> 16) == MessageType.MoveMessageMarker)
                        {
                            var    subQueue = (SubQueue)(0x0000FFFF & message.AppSpecific);
                            string msgId;
                            queueStrategy.TryMoveMessage(queue, message, subQueue, out msgId);
                            Raise(MessageMoved);
                            continue;
                        }
                        string responseQueue = "null://middle/of/nowhere?turn=left";
                        if (message.ResponseQueue != null)
                        {
                            responseQueue = message.ResponseQueue.Path;
                        }
                        logger.DebugFormat("Got message {0} on {1} from {2}",
                                           message.Label,
                                           queue.RootUri,
                                           responseQueue);

                        Raise(TransportMessageArrived);

                        HandlePeekedMessage(queue, message);
                    }
                    catch (ThreadAbortException)
                    {
                        //nothing much to do here, process is being killed
                        //or someone is trying to do something rude to us
                    }
                    catch (Exception e)
                    {
#if DEBUG
                        Debugger.Break();
                        Debug.Fail("should not happen", e.ToString());
#endif
                        logger.Fatal("BUG_IN_THE_BUS: An error occured during message dispatch by the bus itself. Please notify the developers", e);
                    }
                }
        }
コード例 #3
0
        private void MoveToErrorQueue(OpenedQueue queue, Message message, string exceptionText)
        {
            string msgId;

            if (!queueStrategy.TryMoveMessage(queue, message, SubQueue.Errors, out msgId))
            {
                return;
            }
            var desc = new Message
            {
                Label         = ("Error description for: " + message.Label).EnsureLabelLength(),
                Body          = exceptionText,
                CorrelationId = msgId
            }.SetSubQueueToSendTo(SubQueue.Errors);

            queueStrategy.SendToErrorQueue(queue, desc);
            logger.WarnFormat("Moving message {0} to errors subqueue because: {1}", message.Id, exceptionText);
        }
コード例 #4
0
 protected void PeekMessageOnBackgroundThread(object state)
 {
     using (var queue = Endpoint.InitalizeQueue())
         while (!shouldStop)
         {
             try
             {
                 Message message;
                 var     peek = TryPeek(queue, out message);
                 //
                 if (peek == false || shouldStop) // error reading from queue
                 {
                     TransportState = TransportState.FailedToReadFromQueue;
                     return;       // return from method, we have failed
                 }
                 if (peek == null) // nothing was found
                 {
                     continue;
                 }
                 //
                 if ((MessageType)((message.AppSpecific & 0xFFFF0000) >> 16) == MessageType.MoveMessageMarker)
                 {
                     var subQueue = (SubQueue)(0x0000FFFF & message.AppSpecific);
                     using (var tx = new TransactionScope())
                     {
                         string msgId;
                         queueStrategy.TryMoveMessage(queue, message, subQueue, out msgId);
                         tx.Complete();
                     }
                     Raise(MessageMoved);
                     continue;
                 }
                 var responseQueue = "null://middle/of/nowhere?turn=left";
                 if (message.ResponseQueue != null)
                 {
                     responseQueue = message.ResponseQueue.Path;
                 }
                 logger.DebugFormat("Got message {0} on {1} from {2}", message.Label, queue.RootUri, responseQueue);
                 //
                 Raise(TransportMessageArrived);
                 HandlePeekedMessage(queue, message);
             }
             catch (ThreadAbortException) { }
         }                                    // nothing much to do here, process is being killed or someone is trying to do something rude to us