0

I have multiple Cassandra clusters. Each cluster has specific set of contact points. Each cluster has separate set of tables/CF.

In my C* client I am supposed to query both clusters. I am using spring-boot version of the Cassandra. I am trying to use CassandraOperations to do the queries. How do I go about doing this?

@Bean
public CassandraOperations cassandraTemplate(Session sessionA) throws Exception {
     return new CassandraTemplate(sessionA);
}

@Bean
public CassandraMappingContext mappingContext() {
    return new BasicCassandraMappingContext();
}

@Bean
public CassandraConverter converter() {
    return new MappingCassandraConverter(mappingContext());
}

Above is a example whereby I setup cassandraoperations using sessionA, how about doing the same for sessionB?

At any given time base don the query, it can go to either sessionA or sessionB.

Any pointers are appreciated

Thanks

Erick Ramirez
  • 13,964
  • 1
  • 18
  • 23
im2kul
  • 297
  • 1
  • 3
  • 13

1 Answers1

0

Found a way to do this by creating separate classes for each cluster manager.

@Component
@Primary
public class CassandraTemplateA extends CassandraTemplate{

    @Autowired
    public CassandraTemplateA(CassandraConverter converter) {
        super(sessionA, converter);
    }
}

@Component
@Primary
public class CassandraTemplateB extends CassandraTemplate{

    @Autowired
    public CassandraTemplateB(CassandraConverter converter) {
        super(sessionB, converter);
    }
}
im2kul
  • 297
  • 1
  • 3
  • 13
  • can you please share how the two templates are being used or under the hood they are used automatically by Spring and Spring takes care of the two sessions having two different keyspaces? i'm facing a problem in which i need to connect to two different keyspaces. – Charles Aug 28 '17 at 12:13