Created
September 27, 2019 08:42
-
-
Save ramonsmits/fefd68758e928575cf2df3c418641be7 to your computer and use it in GitHub Desktop.
NServiceBus - Sample that shows the flow of context bag extension data from the incoming to outgoing context
This file contains 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
// LogManager.Use<DefaultFactory>().Level(LogLevel.Debug); | |
// var pipeline = endpointConfiguration.Pipeline; | |
// pipeline.Register(new IN(), nameof(IN)); | |
// pipeline.Register(new OUT(), nameof(OUT)); | |
class IN : Behavior<IIncomingLogicalMessageContext> | |
{ | |
public const string Key = "count"; | |
static long count; | |
static readonly ILog Log = LogManager.GetLogger<IN>(); | |
public override Task Invoke(IIncomingLogicalMessageContext context, Func<Task> next) | |
{ | |
var value = Interlocked.Increment(ref count); | |
Log.FatalFormat("count: {0}", value); | |
context.Extensions.Set(Key, value); | |
return next(); | |
} | |
} | |
class OUT : Behavior<IOutgoingLogicalMessageContext> | |
{ | |
static readonly ILog Log = LogManager.GetLogger<OUT>(); | |
public override Task Invoke(IOutgoingLogicalMessageContext context, Func<Task> next) | |
{ | |
var set = context.Extensions.TryGet(IN.Key, out long value); | |
Log.FatalFormat("count: {0} {1}", set, value); | |
return next(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment