Skip to content

[Host.AzureServiceBus] Modify user properties on failure / Supply reason and description on dead-letter#365

Merged
zarusz merged 1 commit into
zarusz:masterfrom
EtherZa:feature/358-failure-properties
Jan 30, 2025
Merged

[Host.AzureServiceBus] Modify user properties on failure / Supply reason and description on dead-letter#365
zarusz merged 1 commit into
zarusz:masterfrom
EtherZa:feature/358-failure-properties

Conversation

@EtherZa

@EtherZa EtherZa commented Jan 29, 2025

Copy link
Copy Markdown
Contributor

#358 Added support for suppliying modified user properties with using an ASB transport when using a custom ServiceBusConsumerErrorHandler<T> implemntation and Failure().

public sealed class SampleConsumerErrorHandler<T> : ServiceBusConsumerErrorHandler<T>
{
    public override Task<ProcessResult> OnHandleError(T message, IConsumerContext consumerContext, Exception exception, int attempts)
    {
        var properties = new Dictionary<string, object>
        {
            { "Key", "value" },
            { "Attempts", attempts },
            { "SMB.Exception", exception.ToString().Substring(0, 1000) }
        };

        return Task.FromResult(Failure(properties));
    }
}

An option to supply a dead-letter reason/description when sending a message to the DLQ has also been included. If neither a reason nor description are supplied, it will fall back to the original implementation of exception type as the reason and exception message as the description.

public sealed class SampleConsumerErrorHandler<T> : ServiceBusConsumerErrorHandler<T>
{
    public override Task<ProcessResult> OnHandleError(T message, IConsumerContext consumerContext, Exception exception, int attempts)
    {
        return Task.FromResult(DeadLetter("reason", "description"));
    }
}

PS. It's great to see that v3 has escaped :)

@EtherZa
EtherZa force-pushed the feature/358-failure-properties branch 2 times, most recently from 9679984 to ff082f0 Compare January 29, 2025 13:34
Comment thread docs/provider_azure_servicebus.md
Comment thread docs/provider_azure_servicebus.md
@zarusz

zarusz commented Jan 29, 2025

Copy link
Copy Markdown
Owner

Thanks for another great change that resolves #358!

I have a small suggestion for the documentation - once that’s addressed, I’ll be happy to merge.

Yes, v3 is out now! If you need this feature sooner, I can release it as 3.0.1 or a similar patch.

@EtherZa

EtherZa commented Jan 30, 2025

Copy link
Copy Markdown
Contributor Author

Hi @zarusz. The feature would be certainly be useful, but it's no rush if you have other plans/etc for a delayed release.

Signed-off-by: Richard Pringle <richardpringle@gmail.com>
@EtherZa
EtherZa force-pushed the feature/358-failure-properties branch from 99e9013 to ef97ce2 Compare January 30, 2025 09:03
@sonarqubecloud

Copy link
Copy Markdown

@zarusz
zarusz merged commit 677cc30 into zarusz:master Jan 30, 2025
@EtherZa

EtherZa commented Feb 3, 2025

Copy link
Copy Markdown
Contributor Author

Hi @zarusz. Is it too late to change my mind on an early release?

I've been told that my team is producing around 100gb of logs a day and reckon that I can reduce it substantially by dynamically changing the logging behaviour on a failure.

@zarusz

zarusz commented Feb 3, 2025

Copy link
Copy Markdown
Owner

Ok, let me push 3.0.1 today.

@EtherZa

EtherZa commented Feb 3, 2025

Copy link
Copy Markdown
Contributor Author

Fantastic! Thank you very much.

@zarusz

zarusz commented Feb 3, 2025

Copy link
Copy Markdown
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants