Skip to content

Instantly share code, notes, and snippets.

@ankitvijay
Last active October 9, 2021 21:31
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
NServiceBus Cosmos Sample - PostIdAsPartitionKeyBehaviour
public class PostIdAsPartitionKeyBehavior: Behavior<IIncomingLogicalMessageContext>
{
public override Task Invoke(IIncomingLogicalMessageContext context, Func<Task> next)
{
if (context.Message.Instance is IPostIdPartitionKey partitionKey)
{
var partitionKeyValue = partitionKey.PostId;
context.Extensions.Set(new PartitionKey(partitionKeyValue));
return next();
}
return next();
}
public class Registration : RegisterStep
{
public Registration() :
base(nameof(PostIdAsPartitionKeyBehavior),
typeof(PostIdAsPartitionKeyBehavior),
"Determines the PartitionKey from the logical message",
b => new PostIdAsPartitionKeyBehavior())
{
InsertBefore(nameof(LogicalOutboxBehavior));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment