Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostgresSQL Event : add usage of Quarkus AgroalDatasource fixes #1909 #1982

Merged
merged 1 commit into from
Nov 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/modules/ROOT/pages/reference/extensions/pgevent.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,31 @@ Please refer to the above link for usage and configuration details.
----

Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.

== Additional Camel Quarkus configuration

You can use pgevent extension with Agroal Datasource.

Add the quarkus-agroal dependency :
[source,xml]
------------------------------------------------------------
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
</dependency>
------------------------------------------------------------

Set Agroal properties, example for named DataSource `pgDatasource` :
-----------
quarkus.datasource.pgDatasource.db-kind=pgsql
quarkus.datasource.pgDatasource.jdbc.url=jdbc:pgsql://localhost:5432/myDB
quarkus.datasource.pgDatasource.username=postgres
quarkus.datasource.pgDatasource.password=mysecretpassword
quarkus.datasource.pgDatasource.jdbc.max-size=16
-----------

Inject the DataSource name in the camel Route, example :
-----------
pgevent:///postgres/testchannel?datasource=#pgDatasource
-----------

4 changes: 4 additions & 0 deletions extensions/pgevent/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-netty-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal-spi</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@
import java.util.stream.Stream;

import com.impossibl.postgres.system.procs.ProcProvider;
import io.quarkus.agroal.spi.JdbcDriverBuildItem;
import io.quarkus.datasource.common.runtime.DatabaseKind;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.SslNativeConfigBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.deployment.util.ServiceUtil;
Expand Down Expand Up @@ -65,4 +68,15 @@ void registerNativeImageResources(BuildProducer<ServiceProviderBuildItem> servic
});
}

/**
* Setting Agroal Datasource driver for pgjdbc-ng driver
*
*/
@BuildStep
void registerDriver(BuildProducer<JdbcDriverBuildItem> jdbcDriver,
SslNativeConfigBuildItem sslNativeConfigBuildItem) {
jdbcDriver.produce(new JdbcDriverBuildItem(DatabaseKind.POSTGRESQL, "com.impossibl.postgres.jdbc.PGDriver",
"com.impossibl.postgres.jdbc.xa.PGXADataSource"));
}

}
5 changes: 5 additions & 0 deletions extensions/pgevent/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-netty</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
<optional>true</optional>
</dependency>
</dependencies>

<build>
Expand Down
24 changes: 24 additions & 0 deletions extensions/pgevent/runtime/src/main/doc/configuration.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
You can use pgevent extension with Agroal Datasource.

Add the quarkus-agroal dependency :
[source,xml]
------------------------------------------------------------
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
</dependency>
------------------------------------------------------------

Set Agroal properties, example for named DataSource `pgDatasource` :
-----------
quarkus.datasource.pgDatasource.db-kind=pgsql
quarkus.datasource.pgDatasource.jdbc.url=jdbc:pgsql://localhost:5432/myDB
quarkus.datasource.pgDatasource.username=postgres
quarkus.datasource.pgDatasource.password=mysecretpassword
quarkus.datasource.pgDatasource.jdbc.max-size=16
-----------

Inject the DataSource name in the camel Route, example :
-----------
pgevent:///postgres/testchannel?datasource=#pgDatasource
-----------
14 changes: 9 additions & 5 deletions integration-tests/pgevent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-bean</artifactId>
<artifactId>camel-quarkus-mock</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
</dependency>

<!-- test dependencies -->
Expand All @@ -75,11 +79,9 @@
<artifactId>camel-quarkus-integration-testcontainers-support</artifactId>
<scope>test</scope>
</dependency>

<!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-pgevent-deployment</artifactId>
<artifactId>camel-quarkus-mock-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand All @@ -94,7 +96,7 @@
<!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-bean-deployment</artifactId>
<artifactId>camel-quarkus-pgevent-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
Expand All @@ -105,6 +107,8 @@
</exclusion>
</exclusions>
</dependency>

<!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-direct-deployment</artifactId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,55 +16,45 @@
*/
package org.apache.camel.quarkus.component.pgevent.it;

import javax.inject.Named;
import javax.ws.rs.Produces;
import javax.enterprise.context.ApplicationScoped;

import com.impossibl.postgres.jdbc.PGDataSource;
import org.apache.camel.builder.RouteBuilder;
import org.eclipse.microprofile.config.inject.ConfigProperty;

@ApplicationScoped
public class PgeventRoutes extends RouteBuilder {

public static final String MOCK_ENDPOINT_CLASSIC_CONF = "mock:classic";
public static final String MOCK_ENDPOINT_AGROALDATASOURCE = "mock:datasource";

@ConfigProperty(name = "database.host")
String host;
@ConfigProperty(name = "database.port")
Integer port;
@ConfigProperty(name = "database.name")
String databaseName;
@ConfigProperty(name = "database.user")
@ConfigProperty(name = "quarkus.datasource.pgDatasource.username")
String user;
@ConfigProperty(name = "database.password")
@ConfigProperty(name = "quarkus.datasource.pgDatasource.password")
String password;

@Override
public void configure() throws Exception {
// producer for simple pub-sub
from("direct:pgevent-pub")
.to("pgevent://{{database.host}}:{{database.port}}/{{database.name}}/testchannel?user={{database.user}}&pass={{database.password}}");
.to(String.format("pgevent://%s:%s/%s/testchannel?user=%s&pass=%s", host, port, databaseName, user, password));

//consumer for simple pub-sub
from("pgevent://{{database.host}}:{{database.port}}/{{database.name}}/testchannel?user={{database.user}}&pass={{database.password}}")
.log("Message got ${body}")
.bean(MyBean.class);
from(String.format("pgevent://%s:%s/%s/testchannel?user=%s&pass=%s", host, port, databaseName, user, password))
.to(MOCK_ENDPOINT_CLASSIC_CONF);

// producer with datasource
from("direct:pgevent-datasource")
.to("pgevent:///postgres/testchannel?datasource=#pgDataSource");
.to("pgevent:///postgres/testchannel?datasource=#pgDatasource");

// consumer with datasource
from("pgevent:///postgres/testchannel?datasource=#pgDataSource")
.log("Message got ${body}")
.bean(MyBean.class);
from("pgevent:///postgres/testchannel?datasource=#pgDatasource")
.to(MOCK_ENDPOINT_AGROALDATASOURCE);
}

@Produces
@Named("pgDataSource")
public PGDataSource loadDataSource() throws Exception {
PGDataSource dataSource = new PGDataSource();
dataSource.setHost(host);
dataSource.setPort(port);
dataSource.setDatabaseName(databaseName);
dataSource.setUser(user);
dataSource.setPassword(password);
return dataSource;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@
# Change the following properties to work with your PostgreSQL instance.
# The default values work with the PostgreSQL docker image https://hub.docker.com/_/postgres/.
# docker run -ti --rm -e POSTGRES_PASSWORD=mysecretpassword -p 5432:5432 postgres

# classic conf
database.name=postgres
database.user=postgres
database.password=mysecretpassword
database.host=localhost
database.port=5432
database.port=5432

#Agroal datasource conf named pgDatasource
quarkus.datasource.pgDatasource.db-kind=pgsql
quarkus.datasource.pgDatasource.jdbc.url=jdbc:pgsql://localhost:5432/postgres
quarkus.datasource.pgDatasource.username=postgres
quarkus.datasource.pgDatasource.password=mysecretpassword
quarkus.datasource.pgDatasource.jdbc.max-size=16
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ public Map<String, String> start() {
"database.port",
container.getMappedPort(POSTGRES_PORT).toString(),
"database.host",
container.getHost());
container.getHost(),
"quarkus.datasource.pgDatasource.jdbc.url",
String.format("jdbc:pgsql://%s:%s/postgres", container.getHost(), container.getMappedPort(POSTGRES_PORT)));
}

@Override
Expand Down