Leonardo Freua
Leonardo Freua

Reputation: 321

Reactive Quarkus: Use Reactive PanacheORM with Multiple datasources

I'm trying to connect to two different databases (both with reactive connection), but I'm not able to create a connection pool for the second database and continue using Panache.

I tried to use the @ReactiveDataSource annotation as it is in the Quarkus documentation, but I can't set this connection for some entities to perform the operations via Panache for this specific pool.

Example (Something like this):

application.properties

quarkus.datasource.db-kind=postgresql 
quarkus.datasource.username=user-default
quarkus.datasource.password=password-default
quarkus.datasource.reactive.url=postgresql://localhost:5432/default

quarkus.datasource."additional1".db-kind=postgresql 
quarkus.datasource."additional1".username=user-additional1
quarkus.datasource."additional1".password=password-additional1
quarkus.datasource."additional1".reactive.url=postgresql://localhost:5432/additional1

User entity

public class User extends PanacheEntity {
    private String name;
}

UserRepository (This is where the Panache configuration for a specific datasource should occur!!)

@ApplicationScoped
public class UserRepository {
    @Inject
    @ReactiveDataSource("additional1")
    PgPool additional1Client;

    public Uni<User> findUserById(int id) {
          // set the _additional1Client_ pool in the Panache to make User.findById(id)........
    }
}

Thanks in advance for any help.

Upvotes: 2

Views: 1505

Answers (2)

Otoniel Silva
Otoniel Silva

Reputation: 37

According to the guides, it is not currently possible to create multiple reactive datasources.

Also, looking forward this feature, but it will be supported only for future Hibernate ORM 6 according to a Quarkus member comment.

Upvotes: 4

jzimmerli
jzimmerli

Reputation: 161

I was checking the guides ant the look exactly what you did. But when i was using name source, I didn't use the ", so try to remove them, might work then. Therfore do:

quarkus.datasource.additional1.db-kind=postgresql 

As described in this artikel: https://quarkus.io/guides/datasource#multiple-datasources

Upvotes: 1

Related Questions