Esempio n. 1
0
        public ReceivedTransportMessage ReceiveMessage(ITransactionContext context)
        {
            var azureMessageQueueTransactionSimulator = new AzureMessageQueueTransactionSimulator(inputQueue);

            try
            {
                var message = azureMessageQueueTransactionSimulator.RetrieveCloudQueueMessage = inputQueue.GetMessage();

                if (message == null)
                {
                    //No message receieved
                    azureMessageQueueTransactionSimulator.Commit();
                    return(null);
                }

                var rawData = message.AsBytes;

                if (rawData == null)
                {
                    log.Warn("Received message with NULL data - how weird is that?");
                    azureMessageQueueTransactionSimulator.Commit();
                    return(null);
                }

                using (var memoryStream = new MemoryStream(rawData))
                {
                    var formatter = new BinaryFormatter();
                    var receivedTransportMessage = (ReceivedTransportMessage)formatter.Deserialize(memoryStream);
                    azureMessageQueueTransactionSimulator.Commit();
                    return(receivedTransportMessage);
                }
            }
            catch (Exception e)
            {
                log.Error(e, "An error occurred while receiving message from {0}", inputQueueName);
                azureMessageQueueTransactionSimulator.Abort();
                return(null);
            }
        }
Esempio n. 2
0
        public ReceivedTransportMessage ReceiveMessage(ITransactionContext context)
        {
            var azureMessageQueueTransactionSimulator = new AzureMessageQueueTransactionSimulator(inputQueue);
            try
            {
                var message = azureMessageQueueTransactionSimulator.RetrieveCloudQueueMessage = inputQueue.GetMessage();

                if (message == null)
                {
                    //No message receieved
                    azureMessageQueueTransactionSimulator.Commit();
                    return null;
                }

                var rawData = message.AsBytes;

                if (rawData == null)
                {
                    log.Warn("Received message with NULL data - how weird is that?");
                    azureMessageQueueTransactionSimulator.Commit();
                    return null;
                }

                using (var memoryStream = new MemoryStream(rawData))
                {
                    var formatter = new BinaryFormatter();
                    var receivedTransportMessage = (ReceivedTransportMessage)formatter.Deserialize(memoryStream);
                    azureMessageQueueTransactionSimulator.Commit();
                    return receivedTransportMessage;
                }
            }
            catch (Exception e)
            {
                log.Error(e, "An error occurred while receiving message from {0}", inputQueueName);
                azureMessageQueueTransactionSimulator.Abort();
                return null;
            }
        }