Skip to content

Instantly share code, notes, and snippets.

@stuartgunter
Last active August 29, 2015 14:01
Show Gist options
  • Save stuartgunter/56a3c43f2fd873a8f6bf to your computer and use it in GitHub Desktop.
Save stuartgunter/56a3c43f2fd873a8f6bf to your computer and use it in GitHub Desktop.
dropwizard-cassandra
# using an exponential reconnection policy
reconnectionPolicy:
type: exponential
baseDelay: 10 milliseconds
maxDelay: 1 second
# using a constant reconnection policy
reconnectionPolicy:
type: constant
delay: 10 milliseconds
<dependency>
<groupId>org.stuartgunter</groupId>
<artifactId>dropwizard-cassandra</artifactId>
<version>${dropwizard-cassandra.version}</version>
</dependency>
public class YourApp extends Application<YourAppConfig> {
private final CassandraBundle<YourAppConfig> cassandra =
new CassandraBundle<YourAppConfig>() {
@Override
protected CassandraFactory cassandraConfiguration(YourAppConfig appConfig) {
return appConfig.getCassandraConfig();
}
};
@Override
public void initialize(Bootstrap<CassandraBundleConfiguration> bootstrap) {
bootstrap.addBundle(cassandra);
}
@Override
public void run(YourAppConfig configuration, Environment environment) throws Exception {
/*
* you can now use `cassandra.getCluster()` to use the cluster instance in your app,
* or pass around a SessionFactory with `cassandra.getSessionFactory()` if you just need
* to be able to create new sessions without knowing whether a keyspace was configured
*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment