Particular / NServiceBus.AzureFunctions.Worker.ServiceBus

Process messages in AzureFunctions using the Azure Service Bus trigger and the NServiceBus message pipeline.
Other
6 stars 3 forks source link

FunctionEndpoint Publish overload ignores PublishOptions argument #572

Open guusschuurcito opened 1 week ago

guusschuurcito commented 1 week ago

Describe the bug

Description

When using the method below, the PublishOptions that have been provided in the options argument are ignored. For example: custom message headers are not included in the event message.

Publish(object message, PublishOptions options, FunctionContext functionContext, CancellationToken cancellationToken = default)

https://github.com/Particular/NServiceBus.AzureFunctions.Worker.ServiceBus/blob/d4df9b9107dfd0bb80b6f006520746f781fed816/src/NServiceBus.AzureFunctions.Worker.ServiceBus/FunctionEndpoint.cs#L101

Expected behavior

PublishOptions that have been provided are also visible in the actual event message, for example custom message headers are included in the event message.

Actual behavior

All options are ignored

Versions

From what i can see all versions above NServiceBus v8 are effected.

Steps to reproduce

Create .NET 8 Isolated Azure function with NServiceBus 8+. Add and configure TestEvent type. Use code below from your function to emit an event.

public class TestPublishService(IFunctionEndpoint functionEndpoint) : ITestPublishService
{
    public Task TestPublish(FunctionContext functionContext)
    {
        var options = new PublishOptions();
        options.SetHeader("TestKey", "TestValue");
        functionEndpoint.Publish(new TestEvent(), options, functionContext);
    }
}

The message will be send, but the header "TestKey" is missing.

Relevant log output

No response

Additional Information

Workarounds

Use the message generator method.

Possible solutions

The problem is clearly visible below. The options argument is not handed over to the endpoint.Publish method, but is not used at all.

public async Task Publish(object message, PublishOptions options, FunctionContext functionContext, CancellationToken cancellationToken = default)
        {
            FunctionsLoggerFactory.Instance.SetCurrentLogger(functionContext.GetLogger("NServiceBus"));
            await InitializeEndpointIfNecessary(cancellationToken).ConfigureAwait(false);
----------->await endpoint.Publish(message, cancellationToken).ConfigureAwait(false); 
        }

https://github.com/Particular/NServiceBus.AzureFunctions.Worker.ServiceBus/blob/d4df9b9107dfd0bb80b6f006520746f781fed816/src/NServiceBus.AzureFunctions.Worker.ServiceBus/FunctionEndpoint.cs#L106

Additional information

WilliamBZA commented 5 days ago

Thanks @guusschuurcito, I'm not sure how this got missed. I've logged it as a bug internally. We'll let you know once it's been fixed.