public static List <ClientConnection> GetSubscribers(Message msg, IList <ClientConnection> clients) { var delimiter = '.'; var result = new List <ClientConnection>(); var topicStack = TopicRouter.ConvertToStack(msg.Topic, delimiter); foreach (var client in clients) { foreach (var subStack in client.TopicStack) { if (MatchTopic(topicStack.Clone(), subStack, false)) { //Add client to subscription list result.Add(client); break; } } } // duga.sde.hde13cb.010.datastorage.1.error.exception.resource already defined // duga.sde.hde13cb.010.datastorage.1.error // duga.#.error // duga.sde.*.*.datastorage.*.error return(result); }
public void Publish(Message msg) { try { //Get subscribers var subs = TopicRouter.GetSubscribers(msg, ClientList); if (subs.Count > 0) { PushMessageToClients(subs.Select(x => x.ConnectionId).ToArray(), msg); } } catch { /* avoid unhandled exceptions */ } }