Esempio n. 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);
            }
        }
Esempio n. 2
0
        public static ServiceBusRuntime MsmqRuntime <T>()
        {
            // Drop test queues if they already exist
            if (MsmqMessageDeliveryQueue.Exists(_testQueuePath))
            {
                MsmqMessageDeliveryQueue.Delete(_testQueuePath);
            }
            if (MsmqMessageDeliveryQueue.Exists(_retryQueuePath))
            {
                MsmqMessageDeliveryQueue.Delete(_retryQueuePath);
            }
            if (MsmqMessageDeliveryQueue.Exists(_failQueuePath))
            {
                MsmqMessageDeliveryQueue.Delete(_failQueuePath);
            }

            // Create test queues
            MsmqMessageDeliveryQueue.Create(_testQueuePath);
            MsmqMessageDeliveryQueue.Create(_retryQueuePath);
            MsmqMessageDeliveryQueue.Create(_failQueuePath);


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

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

            MsmqMessageDeliveryQueue testQueue  = new MsmqMessageDeliveryQueue(_testQueuePath, formatter);
            MsmqMessageDeliveryQueue retryQueue = new MsmqMessageDeliveryQueue(_retryQueuePath, formatter);
            MsmqMessageDeliveryQueue failQueue  = new MsmqMessageDeliveryQueue(_failQueuePath, formatter);

            return(new ServiceBusRuntime(new QueuedDeliveryCore(testQueue, retryQueue, failQueue)));
        }
 public MsmqMessageDeliveryQueue(string path, MessageQueueTransactionType transactionType, IMessageFormatter formatter)
 {
     _queue           = new MessageQueue(path);
     _formatter       = new MessageDeliveryFormatter();
     _transactionType = transactionType;
     _formatter       = formatter;
 }
Esempio n. 4
0
        public ChatServer()
        {
            BinaryMessageEncodingBindingElement element = new BinaryMessageEncodingBindingElement();
            MessageEncoder encoder = element.CreateMessageEncoderFactory().Encoder;

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

            _serviceBus = new ServiceBusRuntime(new DirectDeliveryCore(), new WcfManagementService());
            _serviceBus.AddListener(new ListenerEndpoint(Guid.NewGuid(), "Chat Service", "ChatServer", "http://localhost/chatServer", typeof(IChatService), new WcfServiceHostListener()));
            _serviceBus.Subscribe(new SubscriptionEndpoint(Guid.NewGuid(), "No subscribers", "ChatClient", "", typeof(IChatService), new MethodDispatcher(new UnhandledReplyHandler(_serviceBus)), new UnhandledMessageFilter(typeof(SendMessageRequest)), true));
            _serviceBus.UnhandledException += (o, ex) =>
            {
                Console.WriteLine("Unhandled Exception: " + ex.ExceptionObject);
            };
        }
Esempio n. 5
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();
            }
        }
Esempio n. 6
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);
        }