示例#1
0
        public void Enqueue_Transactions_Abort_Properly()
        {
            recreateQueue();


            BinaryMessageEncodingBindingElement element = new BinaryMessageEncodingBindingElement();
            MessageEncoder encoder = element.CreateMessageEncoderFactory().Encoder;

            MessageDeliveryFormatter formatter = new MessageDeliveryFormatter(new ConverterMessageDeliveryReaderFactory(encoder, typeof(IContract)), new ConverterMessageDeliveryWriterFactory(encoder, typeof(IContract)));

            MsmqMessageDeliveryQueue queue = new MsmqMessageDeliveryQueue(Config.TestQueuePath, formatter);

            SubscriptionEndpoint endpoint = new SubscriptionEndpoint(Guid.NewGuid(), "SubscriptionName", "http://localhost/test", "SubscriptionConfigName", typeof(IContract), new WcfProxyDispatcher(), new PassThroughMessageFilter());

            MessageDelivery enqueued = new MessageDelivery(endpoint.Id, typeof(IContract), "PublishThis", "randomMessageData", 3, new MessageDeliveryContext());

            Assert.IsNull(queue.Peek(TimeSpan.FromSeconds(1))); // make sure queue is null before starting

            // Enqueue, but abort transaction
            using (TransactionScope ts = new TransactionScope())
            {
                queue.Enqueue(enqueued);
            }

            using (TransactionScope ts = new TransactionScope())
            {
                MessageDelivery dequeued = queue.Dequeue(TimeSpan.FromSeconds(5));
                Assert.IsNull(dequeued);
            }
        }
示例#2
0
        public void MessageContractFormatter_Can_Roundtrip_FaultContract()
        {
            recreateQueue();


            BinaryMessageEncodingBindingElement element = new BinaryMessageEncodingBindingElement();
            MessageEncoder encoder = element.CreateMessageEncoderFactory().Encoder;

            MessageDeliveryFormatter formatter = new MessageDeliveryFormatter(new ConverterMessageDeliveryReaderFactory(encoder, typeof(ISendDataContract)), new ConverterMessageDeliveryWriterFactory(encoder, typeof(ISendDataContract)));

            MsmqMessageDeliveryQueue queue = new MsmqMessageDeliveryQueue(Config.TestQueuePath, formatter);
            string action = "sendFault";
            FaultException <SendFault> outgoing = new FaultException <SendFault>(new SendFault()
            {
                Data = "This is a test"
            });

            Dictionary <MessageDeliveryContextKey, object> context = new Dictionary <MessageDeliveryContextKey, object>();

            context.Add(new MessageDeliveryContextKey("test"), "value");

            MessageDelivery outgoingDelivery = new MessageDelivery(Guid.NewGuid(), typeof(ISendDataContract), action, outgoing, 5, new MessageDeliveryContext(context));

            using (TransactionScope ts = new TransactionScope())
            {
                queue.Enqueue(outgoingDelivery);
                ts.Complete();
            }
            using (TransactionScope ts = new TransactionScope())
            {
                MessageDelivery delivery = queue.Dequeue(TimeSpan.FromMinutes(1));
                Assert.AreEqual(typeof(FaultException <SendFault>), delivery.Message.GetType());
                FaultException <SendFault> incoming = (FaultException <SendFault>)delivery.Message;
                Assert.AreEqual(incoming.Data, outgoing.Data);
                Assert.AreEqual(context[new MessageDeliveryContextKey("test")], delivery.Context[new MessageDeliveryContextKey("test")]);

                Assert.AreEqual(outgoingDelivery.Action, delivery.Action);
                Assert.AreEqual(outgoingDelivery.ContractType, delivery.ContractType);
                Assert.AreEqual(outgoingDelivery.MaxRetries, delivery.MaxRetries);
                Assert.AreEqual(outgoingDelivery.MessageDeliveryId, delivery.MessageDeliveryId);
                Assert.AreEqual(outgoingDelivery.RetryCount, delivery.RetryCount);
                Assert.AreEqual(outgoingDelivery.TimeToProcess, delivery.TimeToProcess);
                Assert.AreEqual(outgoingDelivery.SubscriptionEndpointId, delivery.SubscriptionEndpointId);
                ts.Complete();
            }
        }
示例#3
0
        void testMessageDelivery <T>(string messageAction, object messageData)
        {
            Type interfaceType = typeof(T);

            BinaryMessageEncodingBindingElement element = new BinaryMessageEncodingBindingElement();
            MessageEncoder           encoder            = element.CreateMessageEncoderFactory().Encoder;
            MessageDeliveryFormatter formatter          = new MessageDeliveryFormatter(new ConverterMessageDeliveryReaderFactory(encoder, typeof(T)), new ConverterMessageDeliveryWriterFactory(encoder, typeof(T)));


            MsmqMessageDeliveryQueue queue = new MsmqMessageDeliveryQueue(Config.TestQueuePath, formatter);

            SubscriptionEndpoint endpoint = new SubscriptionEndpoint(Guid.NewGuid(), "SubscriptionName", "http://localhost/test", "SubscriptionConfigName", interfaceType, new WcfProxyDispatcher(), new PassThroughMessageFilter());

            MessageDelivery enqueued = new MessageDelivery(endpoint.Id, interfaceType, messageAction, messageData, 3, new MessageDeliveryContext());

            using (TransactionScope ts = new TransactionScope())
            {
                queue.Enqueue(enqueued);
                ts.Complete();
            }

            // Peek
            MessageDelivery dequeued = queue.Peek(TimeSpan.FromSeconds(30));

            Assert.IsNotNull(dequeued);
            Assert.AreEqual(enqueued.Action, dequeued.Action);
            Assert.AreEqual(enqueued.SubscriptionEndpointId, dequeued.SubscriptionEndpointId);

            using (TransactionScope ts = new TransactionScope())
            {
                // Pull for real
                dequeued = queue.Dequeue(TimeSpan.FromSeconds(30));
                ts.Complete();
            }
            Assert.IsNotNull(dequeued);
            Assert.AreEqual(enqueued.Action, dequeued.Action);
            Assert.AreEqual(enqueued.SubscriptionEndpointId, dequeued.SubscriptionEndpointId);

            // Should now be empty
            dequeued = queue.Peek(TimeSpan.FromSeconds(1));
            Assert.IsNull(dequeued);
        }