Quarkus Couchbase
Integrates Couchbase into Quarkus.
This extension is currently in beta status. It supports:
-
Dependency injecting a Couchbase
Cluster
. -
Configuring the Cluster through
application.properties
. Currently, a minimal set of configuration options is provided. -
GraalVM/Mandrel/native-image.
-
KV, Query, Transactions, Analytics, Search and Management operations.
-
Micrometer metrics using
quarkus-micrometer
-
SmallRye Health checks (Readiness) using
quarkus-smallrye-health
-
Dev Services (starts a Couchbase TestContainer, re-usable across tests)
Please try it out and provide feedback, ideas and bug reports on Github.
Usage
Add it to your project:
<dependency>
<groupId>io.quarkiverse.couchbase</groupId>
<artifactId>quarkus-couchbase</artifactId>
<version>{latest-version}</version>
</dependency>
Provide the Couchbase configuration in application.properties
(usually located in your src/main/resources
directory).
See the Configuration section for more options and details.
quarkus.couchbase.connection-string=localhost
quarkus.couchbase.username=username
quarkus.couchbase.password=password
You can now @Inject
a Couchbase Cluster
into your project:
@Path("/couchbase")
public class TestCouchbaseResource {
@Inject
Cluster cluster;
@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/test")
public String run() {
// Get a reference to a particular Couchbase bucket and its default collection
var bucket = cluster.bucket("travel-sample");
var collection = bucket.defaultCollection() ;
// Upsert a new document
collection.upsert("test", JsonObject.create().put("foo", "bar"));
// Fetch and print a document
var doc = bucket.defaultCollection().get("test");
System.out.println("Got doc " + doc.contentAsObject().toString());
// Perform a N1QL query
var queryResult = cluster.query("select * from `travel-sample` where url like 'http://marriot%' and country = 'United States';");
queryResult.rowsAsObject().forEach(row -> {
System.out.println(row.toString());
});
return "Success!";
}
}
And test it at http://localhost:8080/couchbase/test.
Micrometer Metrics
You can enable Micrometer metrics by adding the following dependencies to your application:
# Add Quarkus and Couchbase micrometer dependencies
<dependency>
<groupId>com.couchbase.client</groupId>
<artifactId>metrics-micrometer</artifactId>
<version>0.7.7</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-micrometer</artifactId>
</dependency>
# Here we use Quarkus' Prometheus extension to display metrics in the DevUI
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-micrometer-registry-prometheus</artifactId>
</dependency>
Set quarkus.couchbase.metrics.enabled=true
in application.properties
.
The emission rate is also configurable with quarkus.couchbase.metrics.emit-interval
.
It is recommended to enable histograms which aren’t enabled by default. Configuring the MeterRegistry
is explained on the Quarkus Docs and Couchbase docs.
Unsupported Features
-
Connecting to a Cluster using TLS.
-
The Capella certificate is packaged with the SDK and trusted by default. This enables the extension to connect to a Capella Cluster with the
couchbases://
connection string in dev mode, however there is currently no exposed config item to specify a certificate path or trust store.
-
-
Using the separate
tracing-opentelemetry
package for the Couchbase Java SDK.