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

How to configure Datastax Astra using AbstractCassandraConfiguration #1447

Closed
miladamery opened this issue Oct 19, 2023 · 3 comments
Closed
Labels
type: documentation A documentation update

Comments

@miladamery
Copy link

Hi, I have an app that is using spring(not spring boot) that requires to connect to Datastax Astra DB. There is a solution in case spring boot is available. but that is not an option for me and I couldn't find out how to do this via AbstractReactiveCassandraConfiguration. Thanks in advance.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 19, 2023
@mp911de
Copy link
Member

mp911de commented Oct 23, 2023

AbstractReactiveCassandraConfiguration creates a CQL session when configuring beans.

If you want to build a configuration that is robust against Cassandra absence, then you cannot:

  • Use schema support
  • A configuration built on Abstract…CassandraConfiguration

You also need to provide a SessionFactory implementation to defer session creation to a later time.

@mp911de mp911de added the status: waiting-for-feedback We need additional information before we can continue label Oct 23, 2023
@miladamery
Copy link
Author

miladamery commented Oct 23, 2023

Thanks but I want to ask if this works. I looked at how spring boot configures CqlSession for Astra Db. There is CqlSessionCustomizer that does the job. Spring boot setups CqlSession via a CqlSessionBuilder setting contact points, setting keyspace etc but at the end calling the customizer.
According to this stack question and examples in datastax repos something like below does the job:

@Bean
public CqlSessionBuilderCustomizer sessionBuilderCustomizer(DataStaxAstraProperties astraProperties) {
    Path bundle = astraProperties.getSecureConnectBundle().toPath();
    return builder -> builder.withCloudSecureConnectBundle(bundle);
}

Almost same identical code exists in normal spring data cassandra. in AbstractSessionConfiguration there is method SessionBuilderConfigurer. What happens here is almost the same thing that happens in spring boot. So I wonder if the following does the job of connecting to astra Db with connect bundle file:

public class ReactiveCassandraConfig extends AbstractReactiveCassandraConfiguration {

    private String keySpace;

    private String connectBundlePath;
    @Override
    protected String getKeyspaceName() {
        return keySpace;
    }

    @Override
    protected SessionBuilderConfigurer getSessionBuilderConfigurer() {
        return sessionBuilder -> sessionBuilder
                .withCloudSecureConnectBundle(Path.of(connectBundlePath));
    }
}

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 23, 2023
@mp911de mp911de changed the title Please provide a guide or tutorial on how to connect to Astra DB When no spring boot is available How to configure Datastax Astra using AbstractCassandraConfiguration Oct 25, 2023
@mp911de mp911de added type: documentation A documentation update and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Oct 25, 2023
@mp911de
Copy link
Member

mp911de commented Oct 25, 2023

Sorry, I misunderstood your question and now that you've posted some code, it made it clear what you're asking for. So SessionBuilderConfigurer available on AbstractSessionConfiguration and its subclasses is the way to go.

It makes sense to document SessionBuilderConfigurer in our reference documentation to make it easier to find what you were asking for.

@mp911de mp911de added this to the 4.2 GA (2023.1.0) milestone Oct 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation A documentation update
Projects
None yet
Development

No branches or pull requests

3 participants