/// <summary> /// /// </summary> /// <typeparam name="TMessageSender"></typeparam> /// <typeparam name="TMessage"></typeparam> /// <param name="message"></param> /// <param name="sendAt"></param> public void Schedule <TMessageSender, TMessage>(TMessage message, DateTimeOffset sendAt) where TMessageSender : IMessageSender <TMessage> { var sender = Activator.CreateInstance <TMessageSender>(); var jobId = BackgroundJob.Schedule(() => sender.Send(message), sendAt); // Notify message has added to the send queue var actionContext = new ActionContext { Action = "Message Schedule", ActionTime = DateTime.Now, Data = JsonConvert.SerializeObject(message), JobId = jobId, MessageSenderType = typeof(TMessageSender), MessageType = typeof(TMessage) }; EnqueueSubject.Notify(actionContext); }
/// <summary> /// /// </summary> /// <typeparam name="TMessageSender"></typeparam> /// <typeparam name="TMessage"></typeparam> /// <param name="messages"></param> /// <returns></returns> public void Send <TMessageSender, TMessage>(TMessage[] messages) where TMessageSender : IMessageSender <TMessage> { var sender = Activator.CreateInstance <TMessageSender>(); foreach (var message in messages) { var jobId = BackgroundJob.Enqueue(() => sender.Send(message)); // Notify message has added to the send queue var actionContext = new ActionContext { Action = "Message Enqueue", ActionTime = DateTime.Now, Data = JsonConvert.SerializeObject(message), JobId = jobId, MessageSenderType = typeof(TMessageSender), MessageType = typeof(TMessage) }; EnqueueSubject.Notify(actionContext); } }