/// <summary> /// Defers the message for redelivery using a delayed exchange (an experimental RabbitMQ plug-in). /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context"></param> /// <param name="delay"></param> /// <returns></returns> public static Task Defer <T>(this ConsumeContext <T> context, TimeSpan delay) where T : class { MessageRedeliveryContext redeliveryContext = new DelayedExchangeMessageRedeliveryContext <T>(context); return(redeliveryContext.ScheduleRedelivery(delay)); }
/// <summary> /// Defers the message for redelivery using a delayed exchange (an experimental RabbitMQ plug-in). /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context"></param> /// <param name="delay"></param> /// <param name="callback"></param> /// <returns></returns> public static Task Defer <T>(this ConsumeContext <T> context, TimeSpan delay, Action <ConsumeContext, SendContext> callback = null) where T : class { MessageRedeliveryContext redeliveryContext = new DelayedExchangeMessageRedeliveryContext <T>(context); return(redeliveryContext.ScheduleRedelivery(delay, callback)); }
/// <summary> /// Defers the message for redelivery using a delayed exchange (an experimental RabbitMQ plug-in). /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context"></param> /// <param name="delay"></param> /// <returns></returns> public static Task Defer <T>(this ConsumeContext <T> context, TimeSpan delay) where T : class { var modelContext = context.ReceiveContext.GetPayload <ModelContext>(); var scheduler = new DelayedExchangeMessageScheduler(context, modelContext.ConnectionContext.HostSettings); MessageRedeliveryContext redeliveryContext = new DelayedExchangeMessageRedeliveryContext <T>(context, scheduler); return(redeliveryContext.ScheduleRedelivery(delay)); }
/// <summary> /// Defers the message for redelivery using a delayed exchange (an experimental RabbitMQ plug-in). /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context"></param> /// <param name="delay"></param> /// <param name="callback"></param> /// <returns></returns> public static Task Defer <T>(this ConsumeContext <T> context, TimeSpan delay, Action <ConsumeContext, SendContext> callback = null) where T : class { var modelContext = context.ReceiveContext.GetPayload <ModelContext>(); var scheduler = new DelayedExchangeMessageScheduler(context, modelContext.ConnectionContext.Topology, modelContext.ConnectionContext.HostAddress); MessageRedeliveryContext redeliveryContext = new DelayedExchangeMessageRedeliveryContext <T>(context, scheduler); return(redeliveryContext.ScheduleRedelivery(delay, callback)); }
/// <summary> /// Defers the message for redelivery using a delayed exchange (an experimental RabbitMQ plug-in). /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context"></param> /// <param name="delay"></param> /// <param name="callback"></param> /// <returns></returns> public static Task Defer <T>(this ConsumeContext <T> context, TimeSpan delay, Action <ConsumeContext, SendContext> callback = null) where T : class { if (!context.TryGetPayload(out IMessageScheduler scheduler)) { if (!context.TryGetPayload(out ModelContext modelContext)) { throw new ArgumentException("A valid message scheduler was not found, and no ModelContext was available", nameof(context)); } scheduler = new DelayedExchangeMessageScheduler(context, modelContext.ConnectionContext.Topology, modelContext.ConnectionContext.HostAddress); } MessageRedeliveryContext redeliveryContext = new DelayedExchangeMessageRedeliveryContext <T>(context, scheduler); return(redeliveryContext.ScheduleRedelivery(delay, callback)); }