Example #1
0
        public void Subscription()
        {
            TestUtils.TestApplicationContext context = TestUtils.CreateTestApplicationContext();
            SynchronousQueue <string>        queue   = new SynchronousQueue <string>();
            TestBean     testBean = new TestBean(queue);
            QueueChannel channel  = new QueueChannel();

            context.RegisterChannel("channel", channel);
            Message <string> message = new Message <string>("testing");

            channel.Send(message);
            string polledString;

            Assert.IsFalse(queue.Poll(out polledString));
            MethodInvokingMessageHandler handler = new MethodInvokingMessageHandler(testBean, "foo");
            PollingConsumer endpoint             = new PollingConsumer(channel, handler);

            endpoint.Trigger = new IntervalTrigger(TimeSpan.FromMilliseconds(10));
            context.RegisterEndpoint("testEndpoint", endpoint);
            context.Refresh();
            string result;

            Assert.IsTrue(queue.Poll(TimeSpan.FromMilliseconds(1000), out result));
            Assert.IsNotNull(result);
            Assert.That(result, Is.EqualTo("testing"));
            context.Stop();
        }