NServiceBus Cosmos Sample - PostIdAsPartitionKeyBehaviour
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
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