Inheritance: IDisposable
 public Listener(TopicSubscriber topicSubscriber, IRTDUpdateEvent callback)
 {
     LatestValue = "no update recieved";
     this.rtdUpdateEvent = callback;
     this.TopicSubscriber = topicSubscriber;
     TopicSubscriber.OnMessageRecieved += OnMessageRecieved;
 }
        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);
        }
        public object ConnectData(int rtdTopicId, ref Array strings, ref bool newValues)
        {
            try
            {
                if (!isInitialised)
                {
                    // There was a problem setting up the connection properties
                    // so return the error and leave
                    return lastErrorMsg;
                }

                var topicName = strings.GetValue(0).ToString();

                // Have we all ready subscribed to this Topic
                // if we have we don't want to re-subscribe we can just use the other subscription
                // and have different check values
                var currentTopicSubscriber = GetCurrentTopicSubscriber(topicName);

                if (currentTopicSubscriber==null)
                {
                    // Create a new Consumer
                    currentTopicSubscriber = new TopicSubscriber(session, topicName);
                    currentTopicSubscriber.Start("myConsumerId");
                    currentTopicSubscribers.Add(currentTopicSubscriber);
                }

                var listener = new Listener(currentTopicSubscriber, rtdCallback);

                rtdTopicListeners.Add(rtdTopicId, listener);
                return "connected to ActiveMQ topic: " + topicName;
            }
            catch (Exception ex)
            {
                lastErrorMsg = ex.Message;
                return lastErrorMsg;
            }
        }