DEV Community

Brian King for Couchbase

Posted on • Originally published at couchbase.com on

Announcing General Availability of the Quarkus SDK for Couchbase

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 :

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

<dependency>
    <groupId>io.quarkiverse.couchbase</groupId>
    <artifactId>quarkus-couchbase</artifactId>
    <version>1.0.0</version>
</dependency>
Enter fullscreen mode Exit fullscreen mode

Gradle

dependencies {
     implementation 'io.quarkiverse.couchbase:quarkus-couchbase:1.0.0'
}
Enter fullscreen mode Exit fullscreen mode

2. Configure Your Application

Add your connection string and credentials in application.properties located at src/main/resources/application.properties:

quarkus.couchbase.connection-string=couchbase://localhost
quarkus.couchbase.username=Administrator
quarkus.couchbase.password=password
Enter fullscreen mode Exit fullscreen mode

The extension automatically starts a TestContainer, which can be disabled if desired with:

quarkus.devservices.enabled=false
Enter fullscreen mode Exit fullscreen mode

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.

import jakarta.inject.Inject;
import com.couchbase.client.java.Cluster;

@Inject
Cluster cluster;
Enter fullscreen mode Exit fullscreen mode

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:

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);
     }
}
Enter fullscreen mode Exit fullscreen mode

5. Example: Performing KV Operations

Use the same KV API as in the normal Java SDK:

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();
  }
}
Enter fullscreen mode Exit fullscreen mode

Running your application

Run in dev mode with:

mvn quarkus:dev
Enter fullscreen mode Exit fullscreen mode

And head to the Developer UI at http://localhost:8080/q/dev-ui/welcome.

Or compile to a native executable:

mvn clean install -Dnative -Dmaven.test.skip
Enter fullscreen mode Exit fullscreen mode

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 theCouchbase 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

The post Announcing General Availability of the Quarkus SDK for Couchbase appeared first on The Couchbase Blog.

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

👋 Kindness is contagious

If this article connected with you, consider tapping ❤️ or leaving a brief comment to share your thoughts!

Okay