Created
July 17, 2023 09:32
-
-
Save ramonsmits/0cd03467a1aae03f126712456c8e9bf0 to your computer and use it in GitHub Desktop.
NServiceBus 6+ behavior to run the incoming message
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // If all handlers are compute bound or IO isn't happening early it can result in less concurrent processing as depending on the | |
| // transport and it being full async and no IO is happening message processing could be sequential. This behavior will immediately | |
| // do a Task.Run | |
| // | |
| // Usage: | |
| // endpointConfiguration.Pipeline.Register(new TaskRunBehavior(), nameof(TaskRunBehavior)); | |
| // | |
| class TaskRunBehavior : IBehavior<IIncomingPhysicalMessageContext, IIncomingPhysicalMessageContext> | |
| { | |
| public Task Invoke(IIncomingPhysicalMessageContext context, Func<IIncomingPhysicalMessageContext, Task> next) | |
| { | |
| return Task.Run(() => next(context), context.CancellationToken); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment