示例#1
0
        /// <summary> It will start listening to queue messages to keep the local database up to date
        /// with the changes in the People. But before it starts that, if the local table
        /// is empty, it will fetch the full data. </summary>
        public async Task Subscribe()
        {
            foreach (var item in Subscribers.Values)
            {
                if (await Database.Of(item.DomainType).None())
                {
                    await item.RefreshData();
                }
            }

            PublishQueue.Subscribe <ReplicateDataMessage>(Import);
        }
示例#2
0
 /// <summary>
 /// Attaches an event handler to the specified queue message type.
 /// </summary>
 public static void Subscribe <TMessage>(this IEventBusQueue queue, Func <TMessage, Task> @handler)
     where TMessage : IEventBusMessage
 {
     queue.Subscribe(message =>
     {
         if (message.IsEmpty())
         {
             return(Task.CompletedTask);
         }
         try
         {
             var @event = JsonConvert.DeserializeObject <TMessage>(message);
             return(handler(@event));
         }
         catch (Exception ex)
         {
             throw new Exception("Failed to deserialize event message to " + typeof(TMessage).FullName + ":\r\n" + message, ex);
         }
     });
 }
示例#3
0
        /// <summary> It will start listening to queue messages to keep the local database up to date
        /// with the changes in the People. But before it starts that, if the local table
        /// is empty, it will fetch the full data. </summary>
        public async Task Subscribe()
        {
            await EnsureRefreshData();

            PublishQueue.Subscribe <ReplicateDataMessage>(Import);
        }