Cassandra reactive - Spring data Multitenancy

236 views
Skip to first unread message

Marwa Ajmi

unread,
Mar 23, 2022, 11:51:49 AM3/23/22
to DataStax Java Driver for Apache Cassandra User Mailing List
Hello everyone,

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.

Cédrick Lunven

unread,
Mar 23, 2022, 1:46:43 PM3/23/22
to java-dri...@lists.datastax.com
Hi Marwa,

This is indeed a limitation of the Spring Data Cassandra, it works with a single keyspace, a single CqlSession. 

(Challenging)
  • For what it's worth, having a single runtime accessing multiple keyspaces is a "code smell" as it would be recommended for a component to have it all in a single KS. 
  • Please realize Repositories are limited (no batch, no LWT) and accessing CassandraTemplate and CassandraOperations would be probably required anyway (same data accessed in multi queries)
  • Please learn CQL, some of the features are not available in Spring Data abstraction. 
But you are not out of options:
My2c.
Cedrick.


--
You received this message because you are subscribed to the Google Groups "DataStax Java Driver for Apache Cassandra User Mailing List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to java-driver-us...@lists.datastax.com.
To view this discussion on the web visit https://groups.google.com/a/lists.datastax.com/d/msgid/java-driver-user/6ebf96bd-e8e9-4bf2-88c0-cedd56f1953bn%40lists.datastax.com.


--

Marwa Ajmi

unread,
Mar 24, 2022, 12:10:00 PM3/24/22
to DataStax Java Driver for Apache Cassandra User Mailing List, cedrick...@datastax.com

Hello Cedrick, 

Thanks a lot for your response & support. 
I'll try to implement the second solution, and let you know about it. 

Thanks again.
BR.
Reply all
Reply to author
Forward
0 new messages