Quarkus Reactive
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
- Using
foldlinstead offoldl'causing stack overflow on large lists - Forgetting
deriving (Show, Eq)on custom data types needed for debugging - 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
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