/// <summary> /// Consumes the specified message. /// </summary> /// <param name="message">The message.</param> public override void Consume(TMessage message) { var logString = RockMessage.GetLogString(message); var consumerName = GetType().FullName; var expiration = ConsumeContext.ExpirationTime.HasValue ? ConsumeContext.ExpirationTime.Value.ToLocalTime().ToString() : "None"; Debug.WriteLine($"==================\nConsumer: {consumerName}\nExpiration: {expiration}\n{logString}"); }
/// <inheritdoc cref="SendAsync{TQueue, TMessage}(TMessage)"/> public static Task SendAsync <TQueue>(ICommandMessage <TQueue> message, Type messageType) where TQueue : ISendCommandQueue, new() { RockLogger.Log.Debug(RockLogDomains.Core, "Send Message Async: {@message} Message Type: {1}", message, messageType); if (!IsReady()) { ExceptionLogService.LogException($"A message was sent before the message bus was ready: {RockMessage.GetLogString( message )}"); return(Task.CompletedTask); } var queue = RockQueue.Get <TQueue>(); var endpoint = _transportComponent.GetSendEndpoint(_bus, queue.NameForConfiguration); message.SenderNodeName = NodeName; // NOTE: Use Task.Run to wrap an async instead of directly using async, otherwise async will get an exception if it isn't done before the HttpContext is disposed. return(Task.Run(async() => { await endpoint.Send(message, messageType, context => { context.TimeToLive = RockQueue.GetTimeToLive(queue); }); })); }
/// <inheritdoc cref="PublishAsync{TQueue, TMessage}(TMessage)"/> public static Task PublishAsync <TQueue>(IEventMessage <TQueue> message, Type messageType) where TQueue : IPublishEventQueue, new() { if (!IsReady()) { ExceptionLogService.LogException(new BusException($"A message was published before the message bus was ready: {RockMessage.GetLogString( message )}")); return(Task.CompletedTask); } message.SenderNodeName = NodeName; // NOTE: Use Task.Run to wrap an async instead of directly using async, otherwise async will get an exception if it isn't done before the HttpContext is disposed. return(Task.Run(async() => { await _bus.Publish(message, messageType, context => { context.TimeToLive = RockQueue.GetTimeToLive <TQueue>(); }); })); }
/// <summary> /// Sends the command message. /// </summary> /// <typeparam name="TQueue">The type of the queue.</typeparam> /// <param name="message">The message.</param> /// <param name="messageType">Type of the message.</param> public static async Task SendAsync <TQueue>(ICommandMessage <TQueue> message, Type messageType) where TQueue : ISendCommandQueue, new() { RockLogger.Log.Debug(RockLogDomains.Core, "Send Message Async: {@message} Message Type: {1}", message, messageType); if (!IsReady()) { ExceptionLogService.LogException($"A message was sent before the message bus was ready: {RockMessage.GetLogString( message )}"); return; } var queue = RockQueue.Get <TQueue>(); var endpoint = _transportComponent.GetSendEndpoint(_bus, queue.NameForConfiguration); message.SenderNodeName = NodeName; await endpoint.Send(message, messageType, context => { context.TimeToLive = RockQueue.GetTimeToLive(queue); }); }
/// <summary> /// Publishes the message. /// </summary> /// <typeparam name="TQueue">The type of the queue.</typeparam> /// <param name="message">The message.</param> /// <param name="messageType">Type of the message.</param> public static async Task PublishAsync <TQueue>(IEventMessage <TQueue> message, Type messageType) where TQueue : IPublishEventQueue, new() { if (!IsReady()) { ExceptionLogService.LogException(new BusException($"A message was published before the message bus was ready: {RockMessage.GetLogString( message )}")); return; } message.SenderNodeName = NodeName; await _bus.Publish(message, messageType, context => { context.TimeToLive = RockQueue.GetTimeToLive <TQueue>(); }); }