Connect Quarkus (Reactive) to Neon
Quarkus is a Java framework optimized for cloud environments. This guide shows how to connect to Neon from a Quarkus project using a Reactive SQL Client. To connect to a Lakebase Postgres database fro...
Pre-built prompt for connecting Quarkus applications to Lakebase Postgres using Reactive SQL Client
Quarkus is a Java framework optimized for cloud environments. This guide shows how to connect to Neon from a Quarkus project using a Reactive SQL Client.
To connect to a Lakebase Postgres database from a Quarkus application:
Create a Neon project
If you do not have one already, create a Neon project.
- Navigate to the Projects page in the Neon Console.
- Click New Project.
- Specify your project settings and click Create Project.
Create a Quarkus project
Create a Quarkus project using the Quarkus CLI:
Bash quarkus create app neon-with-quarkus \ --name neon-with-quarkus \ --package-name com.neon.tech \ --extensions reactive-pg-client,resteasy-reactiveYou now have a Quarkus project in a folder named
neon-with-quarkuswith the Reactive Postgres client and RESTEasy Reactive extensions installed.Configure a PostgreSQL data source
Create a
.envfile in the root of your Quarkus project directory. Configure a reactive data source using your database connection string and specifying the database kind as shown:Bash QUARKUS_DATASOURCE_REACTIVE_URL=postgresql://[user]:[password]@[neon_hostname]/[dbname]?sslmode=require&channel_binding=requirenote
You can find the connection details for your database by clicking the Connect button in the Console nav. For more information, see Connect from any application.
Use the Reactive PostgreSQL client
Create a
PostgresResource.javafile in the same directory as theGreetingResource.javathat was generated by Quarkus during project creation. Paste the following content into thePostgresResource.javafile:Java package com.neon.tech; import jakarta.inject.Inject; import io.smallrye.mutiny.Multi; import io.vertx.mutiny.sqlclient.Row; import io.vertx.mutiny.sqlclient.RowSet; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; @Path("/postgres") public class PostgresResource { @Inject io.vertx.mutiny.pgclient.PgPool client; @GET @Path("/version") @Produces(MediaType.TEXT_PLAIN) public Multi<String> getVersion() { return client.query("SELECT version()") .execute() .onItem().transformToMulti(this::extractVersion); } private Multi<String> extractVersion(RowSet<Row> rowSet) { return Multi.createFrom().iterable(rowSet) .map(r -> r.getValue(0).toString()); } }This code defines a HTTP endpoint that will query the database version and return it as a response to incoming requests.
Run the application
Start the application in development mode using the Quarkus CLI from the root of the project directory:
Bash quarkus devVisit localhost:8080/postgres/version in your web browser. Your Neon database's Postgres version will be returned. For example:
PostgreSQL 17.5 (6bc9ef8) on x86_64-pc-linux-gnu, compiled by gcc (Debian 12.2.0-14+deb12u1) 12.2.0, 64-bit
Next steps
Section titled “Next steps”- Add Object Storage: S3-compatible file storage that branches with your database
- Call an LLM with AI Gateway: Access foundation models from Anthropic, OpenAI, Google, and more with one credential
Need help?
Section titled “Need help?”Join our Discord Server to ask questions or see what others are doing with Neon. For paid plan support options, see Support.