Skip to content

Instantly share code, notes, and snippets.

@ankitvijay
Last active October 9, 2021 21:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ankitvijay/6f23605982693594e419c8653633b9b1 to your computer and use it in GitHub Desktop.
Save ankitvijay/6f23605982693594e419c8653633b9b1 to your computer and use it in GitHub Desktop.
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