/// <summary> /// Send a message to a subscription /// </summary> /// <param name="subscription">The subscription the message is destined for</param> /// <param name="data">The message to send to the subscriber</param> void SendMessage(Subscriber subscription, ServiceBusEvent data) { if (!clients.ContainsKey(subscription.SubscriberId)) clients.Add(subscription.SubscriberId, ClientFactory.Connect(subscription.Endpoint)); try { clients[subscription.SubscriberId].Consume(data); Debug.WriteLine("Sent event {0} to client {1}", data.EventName, subscription.SubscriberId); } catch (EndpointNotFoundException) { Unsubscribe(subscription.SubscriberId); } }
/// <summary> /// Removes a subscriber that didn't respond to a heartbeat request /// </summary> /// <param name="sub"></param> void SubscriberTimedOut(Subscriber sub) { Debug.WriteLine("Not feeling a pulse for {0}", sub.SubscriberId); Storage.RemoveSubscriber(sub.SubscriberId); HeartbeatMonitorList.Remove(sub.SubscriberId); }
/// <summary> /// Sends a heartbeat message to a given subscription /// </summary> /// <param name="sub">The subscription to ping</param> void SendHeartBeat(Subscriber sub) { if (!clients.ContainsKey(sub.SubscriberId)) clients.Add(sub.SubscriberId, ClientFactory.Connect(sub.Endpoint)); try { Debug.WriteLine("Checking {0} for a pulse", sub.SubscriberId); clients[sub.SubscriberId].Heartbeat(); HeartbeatMonitorList.Add(sub.SubscriberId); } catch (EndpointNotFoundException) { Unsubscribe(sub.SubscriberId); } }