public void Publish10Messages()
 {
     using (var publisher = new TopicPublisher(session, "Excel.Test.Topic"))
     {
         for (int i = 0; i < 10; i++)
         {
             publisher.SendMessage(DateTime.Now.ToLongTimeString());
             Thread.Sleep(1000);
         }
     }
 }
        public void CanPublishAndSubscribe()
        {
            var messageToSend = DateTime.Now.ToLongTimeString();
            var recievedMessage = "";
            var waitForEvent = new EventWaitHandle(false,EventResetMode.AutoReset);
            using (var subscriber = new TopicSubscriber(session, "Excel.Test.Topic"))
            {
                subscriber.OnMessageRecieved += (sender, m) =>
                                                    {
                                                        waitForEvent.Set();
                                                        recievedMessage = m.Message;
                                                    };
                subscriber.Start("topic consumer");
                using (var publisher = new TopicPublisher(session, "Excel.Test.Topic"))
                {
                    publisher.SendMessage(messageToSend);
                }
                waitForEvent.WaitOne();
            }

            Assert.AreEqual(messageToSend, recievedMessage);
        }