Skip to content

Quarkus Reactive

DodaTech 1 min read

In this tutorial, you'll learn about Fix Quarkus Reactive SQL Not Connecting. We cover key concepts, practical examples, and best practices.

The Problem

Reactive SQL client fails to connect or queries return no results.

Quick Fix

Add reactive SQL dependency

Wrong:

<!-- No reactive client -->

Output:

Cannot connect

Right:

<dependency>
  <groupId>io.quarkus</groupId>
  <artifactId>quarkus-reactive-pg-client</artifactId>
</dependency>

Output:

Reactive PostgreSQL client added

Configure reactive datasource

Wrong:

# No reactive config
quarkus.datasource.reactive.url=vertx-reactive:postgresql://localhost:5432/db

Output:

Not connected

Right:

quarkus.datasource.reactive=true
quarkus.datasource.reactive.url=postgresql://localhost:5432/db
quarkus.datasource.username=user
quarkus.datasource.password=pass

Output:

Reactive datasource configured

Use Uni/Multi return types

Wrong:

@GET public List<Product> getAll() { } // Blocking

Output:

Reactive not used

Right:

@GET
@Route(path = "/products")
public Multi<Product> getAll() {
    return client.query("SELECT * FROM products").execute()
        .onItem().transformToMulti(set -> Multi.createFrom().iterable(set));
}

Output:

Reactive result stream

Prevention

  • Add reactive SQL client dependency
  • Configure reactive datasource properties
  • Use Uni/Multi return types for non-blocking endpoints

Common Mistakes with reactive

  1. Using foldl instead of foldl' causing stack overflow on large lists
  2. Forgetting deriving (Show, Eq) on custom data types needed for debugging
  3. Placing the wildcard pattern first in case expressions, making all subsequent patterns unreachable

These mistakes appear frequently in real-world QUARKUS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What is the difference between reactive SQL and regular JDBC?

Reactive SQL uses non-blocking I/O and returns Uni/Multi instead of blocking on database connections.

This quick fix is part of the DodaTech Spring & JVM ecosystem series. Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro