Cassandra Spring 数据多租户
因此,我即将将多租户(每个租户一个键空间)方面与 spring-boot-starter-data-cassandra-reactive 集成,我尝试找到一种解决方案来访问正确的键空间,我发现了这种使用查询构建器:
Select select = QueryBuilder.select().from(tenantId,"counter");
select.where(QueryBuilder.eq("id", 1));
Mono<Counter> flux = reactiveCassandraOperations.selectOne(select.toString(), Counter.class);
我发现它在开发时间方面成本高昂,特别是如果我们有插入请求.. 根据您的经验,有一个实用的解决方案,我可以使用 ReactiveCassandraRepository 方法(保存、更新、findById ..)插入键空间名称,
请您支持并提前致谢。
So, I'm about to integrate the Multitenancy (one keyspace per tenant) aspect with spring-boot-starter-data-cassandra-reactive, I tried to find a solution to access into the right keyspace and I found this approach of using the query-builder:
Select select = QueryBuilder.select().from(tenantId,"counter");
select.where(QueryBuilder.eq("id", 1));
Mono<Counter> flux = reactiveCassandraOperations.selectOne(select.toString(), Counter.class);
I found it costly in term of development time, especially if we have an insert request ..
Within your experience is there a practical solution where I can insert the keyspace name with the using of the ReactiveCassandraRepository methods ( save, update, findById ..)
Can you support please and thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不是 Cassandra 或 Spring 专家,但我被告知您应该使用 ReactiveCqlTemplate (或 ReactiveCqlOperations)而不是 ReactiveCassandraTemplate (或 ReactiveCassandraOperations)。请参阅此链接 https://github.com/spring-projects/spring -data-cassandra/issues/1218 并点击此页面中的链接。
从链接中,您可以从 CassandraTemplate 获取 CqlOperations,如下所示
然后在您的存储库中
在查询中 genericdatadb 是键空间,YourData 是表。从这里,您可以添加“?”其中 genericdatadb 是或使用 String.format 语句创建查询字符串。也许 Cassandra 专家有更好的解决方案?
Not a Cassandra or Spring expert but I am told that you should use ReactiveCqlTemplate (or ReactiveCqlOperations) rather than ReactiveCassandraTemplate (or ReactiveCassandraOperations). See this link https://github.com/spring-projects/spring-data-cassandra/issues/1218 and follow the links in this page.
From the link, you may get the CqlOperations fronm the CassandraTemplate as follows
And then in your repository
In the query genericdatadb is the keyspace and YourData is the table. From here, you can add a '?' where genericdatadb is or use a String.format statement to create the query String. Maybe there are Cassandra experts with better solutions?