/// <summary> /// Register to receive Messages pertaining to a Topic /// </summary> /// <param name="Topic">The topic to subscribe for</param> /// <param name="consumer">The object that is subscribing for this Topic</param> public void RegisterTopic(string Topic, IMessageDestination consumer) { mLogger.Debug(string.Format("Consumer {0} registered for topic {1}", consumer.GetType(), Topic)); if (ConsumerTopicDictionary.ContainsKey(consumer)) { ConsumerTopicDictionary[consumer].Add(Topic); } else { List <string> list = new List <string>(); list.Add(Topic); ConsumerTopicDictionary.TryAdd(consumer, list); } if (TopicConsumerDictionary.ContainsKey(Topic)) { TopicConsumerDictionary[Topic].Add(consumer); } else { List <IMessageDestination> list = new List <IMessageDestination>(); list.Add(consumer); TopicConsumerDictionary.TryAdd(Topic, list); } }
/// <summary> /// Deregister a consumer from a topic /// </summary> /// <param name="Topic">The topic to degister from</param> /// <param name="consumer">The consumer to deregister</param> public void DeregisterTopic(string Topic, IMessageDestination consumer) { mLogger.Debug(string.Format("Consumer {0} deregistered for topic {1}", consumer.GetType(), Topic)); if (ConsumerTopicDictionary.ContainsKey(consumer)) { ConsumerTopicDictionary[consumer].Remove(Topic); if (ConsumerTopicDictionary[consumer].Count == 0) // There are no more topics for this consumer { List <string> outList = new List <string>(); ConsumerTopicDictionary.TryRemove(consumer, out outList); } } if (TopicConsumerDictionary.ContainsKey(Topic)) { TopicConsumerDictionary[Topic].Remove(consumer); if (TopicConsumerDictionary[Topic].Count == 0) // There are no more consumers for this topic { List <IMessageDestination> outList = new List <IMessageDestination>(); TopicConsumerDictionary.TryRemove(Topic, out outList); } } }