Exemplo n.º 1
0
        public bool HandlePeekedMessage(IMsmqTransport transport, OpenedQueue queue, Message message)
        {
            bool doesNotHaveMessageId = message.Extension.Length < 16;
            if(doesNotHaveMessageId)
            {
                const string errorMessage = "Message does not have Extension set to at least 16 bytes, which will be used as the message id. Probably not a bus message.";
                transport.RaiseMessageSerializationException(queue,message,errorMessage);
                MoveToErrorQueue(queue, message, errorMessage);
                return true;
            }

            var id = message.GetMessageId();
            ErrorCounter errorCounter = null;

            failureCounts.Read(reader => reader.TryGetValue(id, out errorCounter));

            if (errorCounter == null)
                return false;

            if (errorCounter.FailureCount < numberOfRetries)
                return false;

            failureCounts.Write(writer =>
            {
                writer.Remove(id);
                MoveToErrorQueue(queue, message, errorCounter.ExceptionText);
            });

            return true;
        }
Exemplo n.º 2
0
        protected object[] DeserializeMessages(OpenedQueue messageQueue, Message transportMessage, Action<CurrentMessageInformation, Exception> messageSerializationException)
        {
            try
            {
                return messageSerializer.Deserialize(transportMessage.BodyStream);
            }
            catch (Exception e)
            {
                try
                {
                    logger.Error("Error when serializing message", e);
                    if (messageSerializationException != null)
                    {
                        var information = new MsmqCurrentMessageInformation
                        {
                            MsmqMessage = transportMessage,
                            Queue = messageQueue,
                            Message = transportMessage,
                            Source = messageQueue.RootUri,
                            MessageId = transportMessage.GetMessageId(),
                            Headers = transportMessage.Extension.DeserializeHeaders(),
                        };

                        messageSerializationException(information, e);
                    }
                }
                catch (Exception moduleEx)
                {
                    logger.Error("Error when notifying about serialization exception", moduleEx);
                }
                throw;
            }
        }
Exemplo n.º 3
0
 private MsmqCurrentMessageInformation CreateMessageInformation(OpenedQueue queue,Message message, object[] messages, object msg)
 {
     return new MsmqCurrentMessageInformation
     {
         MessageId = message.GetMessageId(),
         AllMessages = messages,
         Message = msg,
         Queue = queue,
         TransportMessageId = message.Id,
         Destination = Endpoint.Uri,
         Source = MsmqUtil.GetQueueUri(message.ResponseQueue),
         MsmqMessage = message,
         TransactionType = queue.GetTransactionType()
     };
 }