Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for configuring partition key extraction rules #69

Closed
danielmarbach opened this issue Oct 7, 2020 · 6 comments · Fixed by #282
Closed

Add support for configuring partition key extraction rules #69

danielmarbach opened this issue Oct 7, 2020 · 6 comments · Fixed by #282
Labels
Milestone

Comments

@danielmarbach
Copy link
Contributor

Raised by @Ivan-L

We found that teams who used our persistence package had a difficult time wrapping their heads around the fact that one needs to look inside a message in order to determine the partition to which a Cosmos session needs to be scoped. We thought of but never got around to it, to implement a fluent API for configuring message partition key extraction rules to make that configuration easier and clearer to reason about. For example, we considered the following:

endpointConfiguration.UsePersistence<CosmosDbPersistence>()
    .CosmosClient(new CosmosClient("ConnectionString"))
    .DatabaseName("DatabaseName")
    .ForMessage<OneSpecificMessage>(message => (new ContainerInformation("containerName", "partitionKeyPath"), message.PartitionKeyValue))
    .ForMessage<ISomeMessageInterface>(message => (new ContainerInformation("containerName", "partitionKeyPath"), message.PartitionKeyValue))
@danielmarbach danielmarbach added the enhancement New feature or request label Oct 7, 2020
@danielmarbach
Copy link
Contributor Author

Additionally, a physical mapping function could also be added, ideas

endpointConfiguration.UsePersistence<CosmosDbPersistence>()
    .CosmosClient(new CosmosClient("ConnectionString"))
    .DatabaseName("DatabaseName")
    .ForMessageWithHeaders<OneSpecificMessage>(headers => (new ContainerInformation("containerName", "partitionKeyPath"), headers["CustomPartitionKeyHeader")) // used to derive the enclosed message type
    .ForHeader(headers=> (new ContainerInformation("containerName", "partitionKeyPath"), headers["CustomPartitionKeyHeader"))) // kind of catch all

@danielmarbach
Copy link
Contributor Author

A bit of context

We actually had helper methods like this at one point but we decided to not add them out of the box and first get a better understanding of what customers do with the flexibility the persister provides before we go down the path of building convenience APIs

@boblangley
Copy link
Member

We started a PR for this and will release it as a new minor shortly.

@boblangley boblangley added this to the 1.1.0 milestone Jan 11, 2022
@danielmarbach danielmarbach changed the title Fluent API for configuring partition key extraction rules Add built-in support for configuring partition key extraction rules Jan 11, 2022
@danielmarbach danielmarbach changed the title Add built-in support for configuring partition key extraction rules Add support for configuring partition key extraction rules Jan 12, 2022
@danielmarbach danielmarbach added Feature and removed enhancement New feature or request labels Jan 20, 2022
@danielmarbach
Copy link
Contributor Author

@Ivan-L We have released 1.1.0. For more details about the release see

https://discuss.particular.net/t/nservicebus-persistence-cosmosdb-1-1-0-minor-release-available/2908

as well as our upgrade guide

https://docs.particular.net/persistence/upgrades/cosmosdb-1to1.1

We have also added comprehensive documentation about the new more convenient transaction API that we introduced in this release

https://docs.particular.net/persistence/cosmosdb/transactions

@Ivan-L
Copy link

Ivan-L commented Jan 20, 2022

Hi @danielmarbach this is really great, thank you! We have a few projects that we can migrate to use this fluent API.

@danielmarbach
Copy link
Contributor Author

@Ivan-L cool! Let us know if you discover loopholes or inconvenient stuff, in case you find any so that we can further improve things in next enhancement releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants