Ejemplo n.º 1
0
 /// <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);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Entry point for subscription events from the server
 /// </summary>
 /// <param name="data">Event data</param>
 public void Consume(ServiceBusEvent data)
 {
     if (Consumer != null)
         Consumer(data);
 }
Ejemplo n.º 3
0
 /// <summary>
 /// Interface method used by clients
 /// </summary>
 /// <param name="data">A message to broadcast</param>
 public void Publish(ServiceBusEvent data)
 {
     Debug.WriteLine("{0} published an event {1} ({2})", data.SourceSubscriber, data.EventName, data.EventId);
     Task.Factory.StartNew(() => Storage.GetSubscribers().ForEach(sub => SendMessage(sub, data)));
     Storage.SubscriberSeen(data.SourceSubscriber);
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Broadcast an event
 /// </summary>
 /// <param name="data">Event data. SourceSubscriber and MessageSent will be set automatically.</param>
 public void Broadcast(ServiceBusEvent data)
 {
     data.SourceSubscriber = myId;
     data.MessageSent = DateTime.Now;
     server.Publish(data);
 }