You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When applying After() middleware that utilizes the messagebus, messages are not sent.
To Reproduce
Sample Code:
// This works when directly injected into my wolverine asp.net handlers, and clients receive the message
public class InformAllClients
{
private IMessageBus _bus;
public InformAllClients(IMessageBus bus)
{
_bus = bus;
}
public async Task Inform(MyAppMessage message)
{
await _bus.SendAsync(new UpdateProcessedNotification() { CommandName= message.GetType().Name });
}
}
// This does get called when registered as middleware, but clients do not receive the message
// options.Policies.ForMessagesOfType<MyAppMessage>().AddMiddleware(typeof(InformAllClientsMiddleware));
public static class InformAllClientsMiddleware
{
public static async Task After(MyAppMessage message, IMessageBus bus)
{
System.Diagnostics.Debug.WriteLine($"Informing {message.GetType().Name}");
await bus.SendAsync(new UpdateProcessedNotification() { CommandName= message.GetType().Name });
}
}
When examining the generated code, we can see this:
public override async System.Threading.Tasks.Task Handle(Microsoft.AspNetCore.Http.HttpContext httpContext)
{
// .... code that does the work
// Have to flush outgoing messages just in case Marten did nothing because of https://github.com/JasperFx/wolverine/issues/536
await messageContext.FlushOutgoingMessagesAsync().ConfigureAwait(false);
await CompounderPlus.Application.Services.InformAllClientsMiddleware.After(command, messageContext).ConfigureAwait(false);
// Wolverine automatically sets the status code to 204 for empty responses
if (!httpContext.Response.HasStarted) httpContext.Response.StatusCode = 204;
}
}
It appears that calling FlushOutgoingMessagesAsync() before it calls the middleware prevents the messages from being sent.
The text was updated successfully, but these errors were encountered:
Describe the bug
When applying After() middleware that utilizes the messagebus, messages are not sent.
To Reproduce
Sample Code:
When examining the generated code, we can see this:
It appears that calling FlushOutgoingMessagesAsync() before it calls the middleware prevents the messages from being sent.
The text was updated successfully, but these errors were encountered: