Weâre excited to announce the General Availability (GA) of the Couchbase Quarkus SDK 1.0, now officially ready for production use! This release brings native integration with the Quarkus framework, enhancing developer productivity and application performance. A standout feature of this release is support for GraalVM native image generation, enabling ultrafast startup times and optimized runtime performance.
Whatâs New in Couchbase Quarkus SDK 1.0?
The new quarkus-couchbase extension integrates our existing Java SDK into Quarkusâ ecosystem. It produces a Cluster object easily accessible with Quarkusâ ArC dependency injection framework, and adds GraalVM compatibility to run the Java SDK as a native executable on any platform.
Seamless GraalVM Native Image Support:
-
- Ultra-fast startup times and reduced memory footprint
- Ideal for cloud-native and serverless environments
Effortless Integration with Quarkus:
-
- Built-in dependency injection for Cluster injection
- Reactive and imperative APIs for flexible development
- Simplified configuration for connectivity
- Micrometer metrics, SmallRye health checks
Open Source Collaboration:
-
- Explore the GitHub repository to contribute and learn
Get Started with Couchbase Quarkus SDK
1. Create a new application
We recommend creating a Quarkus app with the Couchbase Extension via code.quarkus.io. The link will automatically add the Couchbase and REST Quarkus extensions and generate a new sample application.
If you already have an application on hand, add Couchbase as a dependency:
1.1. Add the Dependency
Maven
1 2 3 4 5 |
<dependency> Â Â Â Â <groupId>io.quarkiverse.couchbase</groupId> Â Â Â Â <artifactId>quarkus-couchbase</artifactId> Â Â Â Â <version>1.0.0</version> </dependency> |
Gradle
1 2 3 |
dependencies { implementation 'io.quarkiverse.couchbase:quarkus-couchbase:1.0.0' } |
2. Configure Your Application
Add your connection string and credentials in application.properties
located at src/main/resources/application.properties
:
1 2 3 |
quarkus.couchbase.connection-string=couchbase://localhost quarkus.couchbase.username=Administrator quarkus.couchbase.password=password |
The extension automatically starts a TestContainer, which can be disabled if desired with:
1 |
quarkus.devservices.enabled=false |
Remember to head to the Couchbase Cluster UI at http://localhost:8091 and create a Bucket named default if youâre using DevServices.
3. Injecting the Cluster
The Quarkus Couchbase extension produces a Cluster
bean that can be injected using the @Inject
annotation.
1 2 3 4 5 |
import jakarta.inject.Inject; import com.couchbase.client.java.Cluster; @Inject Cluster cluster; |
From there, its usage is the same as it would be with the normal Java SDK.
4. Example: Creating an HTTP GET Endpoint
Modify the code in src/main/java/org/acme/GreetingResource.java
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
package org.acme; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; import com.couchbase.client.java.Cluster; @ApplicationScoped @Path("couchbase") public class GreetingResource { @Inject Cluster cluster; @GET @Produces(MediaType.TEXT_PLAIN) @Path("simpleQuery") public String simpleQuery() { Â Â Â Â var query = cluster.query("SELECT RAW 'hello world' AS greeting"); Â Â Â Â return query.rowsAs(String.class).get(0); } } |
5. Example: Performing KV Operations
Use the same KV API as in the normal Java SDK:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
package org.acme; import com.couchbase.client.java.Cluster; import com.couchbase.client.java.json.JsonObject; import com.couchbase.client.java.kv.MutationResult; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; @ApplicationScoped @Path("couchbase") public class GreetingResource { @Inject Cluster cluster; @GET @Produces(MediaType.TEXT_PLAIN) @Path("simpleUpsert") public String simpleUpsert() { Â Â Â Â var bucket = cluster.bucket("default"); Â Â Â Â var collection = bucket.defaultCollection(); Â Â Â Â JsonObject content = JsonObject.create() Â Â Â Â Â Â Â Â .put("author", "mike") Â Â Â Â Â Â Â Â .put("title", "My Blog Post 1"); Â Â Â Â MutationResult result = collection.upsert("document-key", content); Â Â Â return result.mutationToken().toString(); Â Â } } |
Running your application
Run in dev mode with:
1 |
mvn quarkus:dev |
And head to the Developer UI at http://localhost:8080/q/dev-ui/welcome.
Or compile to a native executable:
1 |
mvn clean install -Dnative -Dmaven.test.skip |
The native-image will be located in the target directory of your module.
Why Choose Couchbase Quarkus SDK 1.0?
-
- Performance: GraalVM native images provide unparalleled speed and efficiency.
- Flexibility: Seamless integration with Quarkus simplifies development workflows.
- Scalability: Couchbaseâs rich feature set supports applications at any scale.
Ready to Build?
Start building blazing-fast, cloud-native applications today! Explore the Couchbase Quarkus SDK GitHub Repository for more resources, contribute to the project, and share your feedback.
Letâs redefine application performance and developer productivityâtogether!
Community and Support
We believe in the power of community and open-source development. The Quarkus SDK for Couchbase is open-source, and we encourage you to contribute, provide feedback, and join the conversation. For support, if you are our enterprise licensed customer, you can reach out via support, otherwise, you can access our comprehensive documentation, join the Couchbase Forums or Couchbase Discord, or reach out via our support portal.
Further Reading
To learn more, check out our documentation website. It goes into more detail on the API, especially around transactions and asynchronous operations and provides other reference material and sample bindings links for you to dig deeper:
Supported operating systems and compatibility requirements are listed on our documentation website.
Happy coding!
The Couchbase Team