Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed how the DeliverAt header is assigned #6282

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using DeliveryConstraints;
using Extensibility;
using NServiceBus.Routing;
using NUnit.Framework;
Expand Down Expand Up @@ -103,7 +104,7 @@ static async Task<OutgoingMessage> InvokeBehavior(Dictionary<string, string> hea

if (options != null)
{
stash.Set(options);
stash.AddDeliveryConstraint(options.DelayedDeliveryConstraint);
}

await new AttachSenderRelatedInfoOnMessageBehavior()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ namespace NServiceBus
using System;
using System.Threading.Tasks;
using DelayedDelivery;
using NServiceBus.DeliveryConstraints;
using Pipeline;

class AttachSenderRelatedInfoOnMessageBehavior : IBehavior<IRoutingContext, IRoutingContext>
Expand All @@ -27,14 +28,14 @@ public Task Invoke(IRoutingContext context, Func<IRoutingContext, Task> next)

if (!message.Headers.ContainsKey(Headers.DeliverAt))
{
if (context.Extensions.TryGet<SendOptions>(out var options))
if (context.Extensions.TryGetDeliveryConstraint<DelayedDeliveryConstraint>(out var delayedDeliveryConstraint))
{
if (options.DelayedDeliveryConstraint is DelayDeliveryWith delayDeliveryWith)
if (delayedDeliveryConstraint is DelayDeliveryWith delayDeliveryWith)
{
var timeDelay = delayDeliveryWith.Delay;
message.Headers[Headers.DeliverAt] = DateTimeExtensions.ToWireFormattedString(utcNow.Add(timeDelay));
}
else if (options.DelayedDeliveryConstraint is DoNotDeliverBefore doNotDeliverBefore)
else if (delayedDeliveryConstraint is DoNotDeliverBefore doNotDeliverBefore)
{
var deliverAt = doNotDeliverBefore.At;
message.Headers[Headers.DeliverAt] = DateTimeExtensions.ToWireFormattedString(deliverAt);
Expand Down