public void SendAndAsyncReceive()
        {
            listener.MessageCount = 0;

            MessageQueueTemplate q = applicationContext["queueTemplate"] as MessageQueueTemplate;

            Assert.IsNotNull(q);

            q.ConvertAndSend("Hello World 1");
            q.ConvertAndSend("Hello World 2");
            q.ConvertAndSend("Hello World 3");
            q.ConvertAndSend("Hello World 4");
            q.ConvertAndSend("Hello World 5");

            Assert.AreEqual(0, listener.MessageCount);

            transactionalMessageListenerContainer.Start();

            Thread.Sleep(waitInMillis * 2);
            Assert.AreEqual(5, listener.MessageCount);

            transactionalMessageListenerContainer.Stop();
            transactionalMessageListenerContainer.Shutdown();
            Thread.Sleep(2500);
        }
Exemple #2
0
        public void SendAndAsyncReceive()
        {
            //MessageQueueTemplate q = applicationContext["testQueueTemplate"] as MessageQueueTemplate;

            MessageQueueTemplate q = applicationContext["testRemoteTemplate"] as MessageQueueTemplate;

            Assert.IsNotNull(q);

            q.ConvertAndSend("Hello World 1");
            q.ConvertAndSend("Hello World 2");
            q.ConvertAndSend("Hello World 3");
            q.ConvertAndSend("Hello World 4");
            q.ConvertAndSend("Hello World 5");

            //Reset the state so that running all tests together will succeed.
            exceptionHandler.MessageCount = 0;

            Assert.AreEqual(0, listener.MessageCount);

            container.Start();

            Thread.Sleep(waitInMillis);
            Assert.AreEqual(5, listener.MessageCount);
            Assert.AreEqual(0, exceptionHandler.MessageCount);

            container.Stop();
            container.Shutdown();
            Thread.Sleep(2500);
        }
        public void SendAndAsyncReceiveWithExceptionHandling()
        {
            MessageQueueTemplate q = applicationContext["queueTemplate"] as MessageQueueTemplate;

            Assert.IsNotNull(q);

            MessageQueueTemplate retryQ = applicationContext["retryQueueTemplate"] as MessageQueueTemplate;

            Assert.IsNotNull(retryQ);

            q.ConvertAndSend("Goodbye World 1");

            Assert.AreEqual(0, listener.MessageCount, "PRECONDITION FAILURE: Unable to send the message!");

            distributedTxMessageListenerContainer.Start();

            Thread.Sleep(waitInMillis);

            distributedTxMessageListenerContainer.Stop();
            distributedTxMessageListenerContainer.Shutdown();
            Thread.Sleep(2500);

            object msg = retryQ.ReceiveAndConvert();

            Assert.IsNotNull(msg);
            string textMsg = msg as string;

            Assert.IsNotNull(textMsg);
            Assert.AreEqual("Goodbye World 1", textMsg);
        }
        public void SendAndAsyncReceiveWithExceptionHandling()
        {
            listener.MessageCount = 0;

            MessageQueueTemplate q = applicationContext["queueTemplate"] as MessageQueueTemplate;

            Assert.IsNotNull(q);

            MessageQueueTemplate retryQ = applicationContext["retryQueueTemplate"] as MessageQueueTemplate;

            Assert.IsNotNull(retryQ);

            q.ConvertAndSend("Goodbye World 1");

            Assert.AreEqual(0, listener.MessageCount);
            transactionalMessageListenerContainer.Start();

            Thread.Sleep(waitInMillis);


            transactionalMessageListenerContainer.Stop();
            transactionalMessageListenerContainer.Shutdown();
            Thread.Sleep(2500);

            object msg = retryQ.ReceiveAndConvert();

            Assert.IsNotNull(msg);
            string textMsg = msg as string;

            Assert.IsNotNull(textMsg);
            Assert.AreEqual("Goodbye World 1", textMsg);
        }
        public void SendAndAsyncReceive()
        {
            const int MESSAGE_COUNT = 5;

            //must match the retry count in the object registration for test to pass!
            //const int EXCEPTION_QUEUE_RETRY_COUNT = 2;

            int expectedMessageCount = MESSAGE_COUNT; // +(MESSAGE_COUNT * EXCEPTION_QUEUE_RETRY_COUNT);

            MessageQueueTemplate q = applicationContext["queueTemplate"] as MessageQueueTemplate;

            Assert.IsNotNull(q);

            for (int i = 0; i < MESSAGE_COUNT; i++)
            {
                q.ConvertAndSend(String.Format("Hello World {0}", (i + 1)));
            }

            Assert.AreEqual(0, listener.MessageCount);

            distributedTxMessageListenerContainer.Start();

            Thread.Sleep(10000);

            /*
             * System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
             * timer.Start();
             *
             * while (listener.MessageCount < expectedMessageCount)
             * {
             *  if (timer.ElapsedMilliseconds > 10000)
             *  {
             *      break;
             *  }
             *      //Assert.Fail("Did not receive expected number of messages within the permitted time limit.");
             *  Thread.Sleep(1000);
             * }
             *
             * timer.Stop();
             *
             * System.Diagnostics.Debug.WriteLine("elapsed time = " + timer.ElapsedMilliseconds);
             */

            Assert.AreEqual(expectedMessageCount, listener.MessageCount);

            distributedTxMessageListenerContainer.Stop();
            distributedTxMessageListenerContainer.Shutdown();
            Thread.Sleep(2500);

            MessageQueueTemplate responseQ = applicationContext["responseQueueTemplate"] as MessageQueueTemplate;

            responseQ.ReceiveTimeout = new System.TimeSpan(0, 0, 2);

            Assert.IsNotNull(responseQ);
            for (int i = 0; i < MESSAGE_COUNT; i++)
            {
                Assert.IsNotNull(responseQ.ReceiveAndConvert());
            }
        }
        public void Test()
        {
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();

            MessageQueueTemplate q = applicationContext["testQueueTemplate"] as MessageQueueTemplate;

            Assert.IsNotNull(q);

            q.ConvertAndSend("Hello World 1");
            q.ConvertAndSend("Hello World 2");
            q.ConvertAndSend("Hello World 3");
            q.ConvertAndSend("Hello World 4");
            q.ConvertAndSend("Hello World 5");

            //Reset the state so that running all tests together will succeed.
            exceptionHandler.MessageCount = 0;

            Assert.AreEqual(0, listener.MessageCount);

            timer.Start();

            container.Start();

            while (listener.MessageCount < 5)
            {
                //provide an exit if the test is completely over-length
                if (timer.ElapsedMilliseconds > 120000)
                {
                    Assert.Fail("Did not receive expected number of messages with the expected time-limit!");
                }
            }

            timer.Stop();

            container.Stop();
            container.Shutdown();

            Debug.WriteLine(String.Format("Elapsed Milliseconds: {0}", timer.ElapsedMilliseconds));

            Assert.Less(timer.ElapsedMilliseconds, 50000);
            Assert.AreEqual(5, listener.MessageCount);
            Assert.AreEqual(0, exceptionHandler.MessageCount);
        }
 public void Send(TradeRequest tradeRequest)
 {
     // post process message from conversion before sending
     MessageQueueTemplate.ConvertAndSend(tradeRequest, delegate(Message message)
     {
         message.ResponseQueue = GetResponseQueue();
         message.AppSpecific   = random.Next();
         return(message);
     });
 }
 public void SendMarketData()
 {
     while (true)
     {
         string data = GenerateFakeMarketData();
         log.Info("Sending market data.");
         MessageQueueTemplate.ConvertAndSend(data);
         log.Info("Sleeping " + sleepTimeInSeconds + " seconds before sending more market data.");
         Thread.Sleep(sleepTimeInSeconds);
     }
 }
Exemple #9
0
        public void SendAndAsyncReceiveWithExceptionHandling()
        {
            MessageQueueTemplate q = applicationContext["testQueueTemplate"] as MessageQueueTemplate;

            Assert.IsNotNull(q);
            q.ConvertAndSend("Goodbye World 1");
            Assert.AreEqual(0, listener.MessageCount);
            container.Start();
            Thread.Sleep(waitInMillis);
            Assert.AreEqual(0, listener.MessageCount);
            Assert.AreEqual(1, exceptionHandler.MessageCount);
            container.Stop();
            container.Shutdown();
            Thread.Sleep(2500);
        }
Exemple #10
0
 public void Send(IDictionary <string, object> logMessage)
 {
     MessageQueueTemplate.ConvertAndSend(JsonConvert.SerializeObject(logMessage));
 }