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

It is unnecessarily hard to send messages from recoverability #6973

Open
danielmarbach opened this issue Mar 12, 2024 · 0 comments
Open

It is unnecessarily hard to send messages from recoverability #6973

danielmarbach opened this issue Mar 12, 2024 · 0 comments

Comments

@danielmarbach
Copy link
Contributor

Describe the feature.

Is your feature related to a problem? Please describe.

While in general there are cases where it makes sense to find other ways instead of trying to send messages from recoverability, here are valid use cases to do so. Here is an example from a customer case:

image

We have a client Application which starts a Saga. The saga receives a zip file(package) and must distributed it to different services. For each service there is a specific handler made for.

The handler makes an http POST request to an API. For this request we use a httpclient component not made by ourselves. This httpclient component gives back an OK or an ApiException. In that case we immediately send back a PackagePublished failed event So the saga can complete with a reply to the client with the state of failed.

Now if there is any other exception maybe by the handler itself or by the httpclient we are going into the NServicebus default retries. After the retries the message is going into the error queue. Now when it does go to error queue we also want to complete the saga. So the idea is to use the recoverability failed notification with the FailedMessage and if the failed message is of type PublishPackage then make a PackagePublishedFailed message for the saga.

More details in case 00085737

Currently the error notification delegates do not give access to any means of sending messages (nor the service provider to resolve something). The recoverability pipeline stages are working on a very low-level routing and are not really suitable for sending out higher level messages. So currently the only way to achieve this is by adding a behavior into the recoverability stage that gets access to the message session

class RecoverabilityBehavior(IMessageSession messageSession, ILogger<RecoverabilityBehavior> logger) : Behavior<IRecoverabilityContext>
{
    public override async Task Invoke(IRecoverabilityContext context, Func<Task> next)
    {
        if (context.RecoverabilityAction is MoveToError && context.Metadata.TryGetValue("NServiceBus.ExceptionInfo.Data.Message type", out var messageType) && messageType.Equals(nameof(MyMessage)))
        {
            logger.LogInformation("MyMessage failed. Publishing MyMessageFailed event.");
            var message = new MyMessageFailed();
            await messageSession.Publish(message, context.CancellationToken);
        }

        await next();
    }
}

On top of that here is no more any batching guarantees available even though we could probably support it in various transports.

Describe the requested feature

Have an ability to send/publish messages from recoverability.

Describe alternatives you've considered

Additional Context

No response

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

No branches or pull requests

1 participant