{"id":13806174,"url":"https://github.com/composable-systems/dropwizard-cassandra","last_synced_at":"2025-10-04T16:31:54.511Z","repository":{"id":16986705,"uuid":"19749649","full_name":"composable-systems/dropwizard-cassandra","owner":"composable-systems","description":"Dropwizard support for Cassandra","archived":true,"fork":false,"pushed_at":"2017-04-12T02:20:55.000Z","size":333,"stargazers_count":58,"open_issues_count":3,"forks_count":23,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-06T20:11:39.801Z","etag":null,"topics":["cassandra","datastax-cassandra-driver","dropwizard","dropwizard-cassandra","java"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/composable-systems.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-13T17:56:56.000Z","updated_at":"2023-01-28T19:36:26.000Z","dependencies_parsed_at":"2022-08-30T18:02:06.475Z","dependency_job_id":null,"html_url":"https://github.com/composable-systems/dropwizard-cassandra","commit_stats":null,"previous_names":["stuartgunter/dropwizard-cassandra"],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/composable-systems%2Fdropwizard-cassandra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/composable-systems%2Fdropwizard-cassandra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/composable-systems%2Fdropwizard-cassandra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/composable-systems%2Fdropwizard-cassandra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/composable-systems","download_url":"https://codeload.github.com/composable-systems/dropwizard-cassandra/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235285436,"owners_count":18965324,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cassandra","datastax-cassandra-driver","dropwizard","dropwizard-cassandra","java"],"created_at":"2024-08-04T01:01:08.522Z","updated_at":"2025-10-04T16:31:49.218Z","avatar_url":"https://github.com/composable-systems.png","language":"Java","funding_links":[],"categories":["Open Source"],"sub_categories":["Data Stores"],"readme":"# dropwizard-cassandra\n\n[![Build Status](https://travis-ci.org/composable-systems/dropwizard-cassandra.png?branch=master)](https://travis-ci.org/composable-systems/dropwizard-cassandra)\n\nThe `dropwizard-cassandra` library provides useful functionality for Dropwizard apps that communicate with [Cassandra](http://cassandra.apache.org) clusters.\nUnder the hood, it uses the [DataStax Cassandra Driver](http://www.datastax.com/documentation/developer/java-driver/3.0/java-driver/whatsNew2.html).\n\n## What's Included\n\nBy default, the bundle includes:\n\n* Configuration\n* Managed Cluster\n* Health Check\n* Metrics\n* Support for multiple clusters\n* Injected Cluster and Session instances\n\n### Configuration\n\nA configuration class is defined for you with sensible defaults (wherever possible, relying on those provided by the driver).\nAll you need to do is override the default configuration as required and then let the `CassandraFactory` do the work of\nwiring everything up correctly.\n\n### Managed Cluster\n\nThe `Cluster` instance is wrapped as a `Managed` object in Dropwizard, allowing it to be properly closed when the application\nterminates. Graceful termination is attempted first (with a configurable wait period), after which the cluster will be\nforcefully terminated. Remember that we're talking about the client driver being closed... not the actual Cassandra cluster.\n\n### Health Check\n\nA health check is registered automatically for you, ensuring that your application reports the correct status based on\nits ability to connect to Cassandra. The cluster is considered healthy if it can successfully execute the `validationQuery`\ndefined in configuration.\n\n### Metrics\n\nDataStax already expose metrics directly from the Cluster instance, but `CassandraFactory` extracts and registers them\nwith the `MetricRegistry` of your app - ensuring that they get correctly reported.\n\n### Support for Multiple Clusters\n\nFor apps that connect to multiple Cassandra clusters, all features described above are fully supported through separation\nby named clusters. Health checks and metrics are named according to cluster, allowing multiple separate clusters to\noperate safely within the same application.\n\n\n## Usage\n\nUsing the bundle is as simple as registering it in your Dropwizard application. The dependency can be found in Maven Central\nwith the following coordinates:\n\n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003esystems.composable\u003c/groupId\u003e\n  \u003cartifactId\u003edropwizard-cassandra\u003c/artifactId\u003e\n  \u003cversion\u003e${dropwizard-cassandra.version}\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nOnce you have the dependency registered, it's just a matter of adding `CassandraFactory` instances to your \n`Configuration` class:\n\n```java\npublic class YourAppConfig extends Configuration {\n\n    @Valid\n    @NotNull\n    private CassandraFactory cassandra = new CassandraFactory();\n\n    @JsonProperty(\"cassandra\")\n    public CassandraFactory getCassandraFactory() {\n        return cassandra;\n    }\n\n    @JsonProperty(\"cassandra\")\n    public void setCassandraFactory(CassandraFactory cassandra) {\n        this.cassandra = cassandra;\n    }\n}\n```\n\nThen, in your `Application`, build `Cluster` instances when you need them:\n\n```java\npublic class YourApp extends Application\u003cYourAppConfig\u003e {\n    \n    @Override\n    public void run(YourAppConfig configuration, Environment environment) throws Exception {\n        Cluster cassandra = configuration.getCassandraFactory().build(environment);\n    }\n}\n```\n\nOr, you may setup automatic injection of `Cluster` or `Session` instances into your resources.\nTo do that, just add `CassandraBundle` class into your bootstrap:\n\n```java\npublic class YourApp extends Application\u003cYourAppConfig\u003e {\n\t\n    @Override\n    public void initialize(final Bootstrap\u003cYourAppConfig\u003e bootstrap) {\n     //...\n     bootstrap.addBundle(new CassandraBundle\u003cYourAppConfig\u003e() {\n        @Override\n        public CassandraFactory getCassandraFactory(YourAppConfig configuration) {\n            return configuration.getCassandraFactory();\n        }\n     });\n     //...\n    }\n}\n```\n\nand then you're able to inject Cassandra dependencies into your resources. You may either provide a `Cluster` instance:\n\n```java\n@Path(\"/test\")\npublic class TestService {\n\n    @Context Cluster cluster;\n\n    @Produces(MediaType.APPLICATION_JSON)\n    @GET\n    @Path(\"/users\")\n    public List\u003cUser\u003e getUsers() {\n        try (final Session session = cluster.connect(\"auth\")) {\n            final ResultSet resultSet = session.execute(\"SELECT * FROM users\");\n            //...\n        }\n    }\n}\n```\n\nor `Session` instance:\n\n```java\n@Path(\"/test\")\npublic class TestService {\n\n    @Produces(MediaType.APPLICATION_JSON)\n    @GET\n    @Path(\"/users\")\n    public List\u003cUser\u003e getUsers(@Context Session session) {\n        final ResultSet resultSet = session.execute(\"SELECT * FROM users\");\n        //...\n    }\n}\n```\n\nIf you use injected `Session` instance, then session is opened with keyspace that is defined in your application\nconfiguration for Cassandra (see `CassandraFactory.getKeyspace()`). If keyspace isn't specified in your configuration,\nthen session will be opened with no defined keyspace, so that you have to explicitly specify it in statements for\ntables/column families.\n\n## Configuration Reference\n\nThe `dropwizard-cassandra` library defines a number of configuration options that are largely based on the requirements\nof the DataStax Cassandra driver. Some additional configuration is included for the bundle to register everything correctly\nwith Dropwizard.\n\nThe full set of configuration options are shown below. Only configuration keys are shown; please see the JavaDocs on the various\nconfiguration classes for more details about the configuration options available and their default values - particularly\nfor polymorphic configuration - e.g. `ReconnectionPolicyFactory`. There are also a number of smoke tests ensuring\nthat the major configuration options are parseable. To find examples of particular config variants, take a look at the\n[test resources](src/test/resources) folder.\n\n`contactPoints` now support entries that resolve to multiple `InetAddress`es. In this case, every address resolved will\nbe added to the cluster. This is particularly useful when your Cassandra nodes are handled by an external service discovery\nplatform. For more information see [here](http://docs.datastax.com/en/drivers/java/3.0/com/datastax/driver/core/Cluster.Builder.html#addContactPoints-java.lang.String-)\n\n```yaml\nclusterName:\nkeyspace:\nvalidationQuery:\nhealthCheckTimeout:\ncontactPoints:\nport:\nprotocolVersion:\ncompression:\nmaxSchemaAgreementWait:\nssl:\n  type:\naddressTranslator:\n  type:\nreconnectionPolicy:\n  type:\nauthProvider:\n  type:\nretryPolicy:\n  type:\nloadBalancingPolicy:\n  type:\nspeculativeExecutionPolicy:\n  type:\nqueryOptions:\n  consistencyLevel:\n  serialConsistencyLevel:\n  fetchSize:\nsocketOptions:\n  connectTimeoutMillis:\n  readTimeoutMillis:\n  keepAlive:\n  reuseAddress:\n  soLinger:\n  tcpNoDelay:\n  receiveBufferSize:\n  sendBufferSize:\npoolingOptions:\n  heartbeatInterval:\n  poolTimeout:\n  local:\n    maxRequestsPerConnection:\n    newConnectionThreshold:\n    coreConnections:\n    maxConnections:\n  remote:\n    maxRequestsPerConnection:\n    newConnectionThreshold:\n    coreConnections:\n    maxConnections:\nmetricsEnabled:\njmxEnabled:\nshutdownGracePeriod:\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomposable-systems%2Fdropwizard-cassandra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcomposable-systems%2Fdropwizard-cassandra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomposable-systems%2Fdropwizard-cassandra/lists"}