Skip to content

Commit

Permalink
Simplify support for Quartz clustering
Browse files Browse the repository at this point in the history
Fixes #3850
  • Loading branch information
jamesnetherton committed Jun 29, 2022
1 parent 29b4455 commit a3e8105
Show file tree
Hide file tree
Showing 26 changed files with 624 additions and 504 deletions.
9 changes: 9 additions & 0 deletions docs/modules/ROOT/pages/migration-guide/2.11.0.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
= Camel Quarkus 2.11.0 Migration Guide

The following guide outlines how to adapt your code to changes that were made in Camel Quarkus 2.11.0 & Quarkus 2.11.0.Final.

== Changes to Quartz clustering support

In previous releases the Camel Quarkus Quartz documention listed various means of configuring Quartz for clustering. This has now been simplified
to a single set of instructions that leverages Quarkus Quartz. If you are using one of the previous methods of clustering, it is advised to update your
application to the new method documented in the xref:reference/extensions/quartz.adoc[Quartz extension guide].
1 change: 1 addition & 0 deletions docs/modules/ROOT/pages/migration-guide/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ We do frequent releases, a release almost every month, and even though we strive

Listed here are guides on how to migrate between major versions and anything of significance to watch for when upgrading from minor versions.

* xref:migration-guide/2.11.0.adoc[Camel Quarkus 2.10.0 to Camel Quarkus 2.11.0 migration guide]
* xref:migration-guide/2.10.0.adoc[Camel Quarkus 2.9.0 to Camel Quarkus 2.10.0 migration guide]
* xref:migration-guide/2.8.0.adoc[Camel Quarkus 2.7.0 to Camel Quarkus 2.8.0 migration guide]
* xref:migration-guide/2.7.0.adoc[Camel Quarkus 2.6.0 to Camel Quarkus 2.7.0 migration guide]
Expand Down
116 changes: 63 additions & 53 deletions docs/modules/ROOT/pages/reference/extensions/quartz.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -43,65 +43,75 @@ Check the xref:user-guide/index.adoc[User guide] for more information about writ

=== Clustering

There are two options how to run Quartz in clustered mode:
Support for Quartz clustering is provided by the Quarkus Quartz extension. The follow steps outline how to configure Quarkus Quartz for use with Camel.

==== Quarkus based

This is the preferred option. Follow the https://quarkus.io/guides/quartz[scheduling periodic tasks quartz guide].

- Define database configuration in `application.properties`.
- Use for example `flyway` to create database tables required for `Quartz`.

===== Quartz based with an Agroal datasource

Follow the http://www.quartz-scheduler.org/documentation/quartz-1.8.6/configuration/ConfigJDBCJobStoreClustering.html#configure-clustering-with-jdbc-jobstore[Configure Clustering with JDBC-JobStore Guide] with different DS configuration:

- Declare to use `io.quarkus:quarkus-agroal` in `pom.xml` explicitly.
1. Enable Quartz clustered mode and configure a `DataSource` as a persistence Quartz job store. An example configuration is as follows.
+
[source,properties]
----
# Quartz configuration
quarkus.quartz.clustered=true
quarkus.quartz.store-type=jdbc-cmt
quarkus.quartz.start-mode=forced
# Datasource configuration
quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=quarkus_test
quarkus.datasource.password=quarkus_test
quarkus.datasource.jdbc.url=jdbc:postgresql://localhost/quarkus_test
# Optional automatic creation of Quartz tables
quarkus.flyway.connect-retries=10
quarkus.flyway.table=flyway_quarkus_history
quarkus.flyway.migrate-at-start=true
quarkus.flyway.baseline-on-migrate=true
quarkus.flyway.baseline-version=1.0
quarkus.flyway.baseline-description=Quartz
----

```
2. Add the correct JDBC driver extension to your application that corresponds to the value of `quarkus.datasource.db-kind`. In the above
example `postgresql` is used, therefore the following JDBC dependency would be required. Adjust as necessary for your needs. Agroal is also required
for `DataSource` support.
+
[source,xml]
----
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
</dependency>
```

- Use `quartz.properties` to configure the `JobStore`.
- Define a datasource via quarkus (see the https://quarkus.io/guides/datasource[Quarkus datasource documentation)] and use `CamelQuarkusQuartzConnectionProvider` as the `ConnectionProvider` in `quartz.properties`:

```
...
org.quartz.jobStore.dataSource = myDS

# datasource configuration
org.quartz.dataSource.myDS.connectionProvider.class = org.apache.camel.quarkus.component.quartz.CamelQuarkusQuartzConnectionProvider
org.quartz.dataSource.myDSB.dataSourceName = ds_name_if_not_set_default_ds_will_be_used
```


- You can use for example `flyway` to create database tables required for `Quartz`.

===== Quartz based

You can follow the http://www.quartz-scheduler.org/documentation/quartz-1.8.6/configuration/ConfigJDBCJobStoreClustering.html#configure-clustering-with-jdbc-jobstore[Configure Clustering with JDBC-JobStore Guide] without any modification:

```
...
org.quartz.jobStore.dataSource = myDS

# datasource configuration
org.quartz.dataSource.myDS.driver = org.postgresql.Driver

# datasource configuration
org.quartz.dataSource.myDS.URL=jdbc:postgresql://localhost:5432/default
org.quartz.dataSource.myDS.user = quarkus
org.quartz.dataSource.myDS.password = quarkus
```


== Camel Quarkus limitations
----

=== JDBC Job Store
3. https://quarkus.io/guides/flyway[Quarkus Flyway] can automatically create the necessary Quartz database tables for you. Add `quarkus-flyway` to your application (optional).
+
[source,xml]
----
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-flyway</artifactId>
</dependency>
----
+
Also add a Quartz database creation script for your chosen database kind.
The Quartz project provides ready made scripts that can be copied from https://github.com/quartz-scheduler/quartz/tree/master/quartz-core/src/main/resources/org/quartz/impl/jdbcjobstore[here]. Add the SQL
script to `src/main/resources/db/migration/V1.0.0__QuarkusQuartz.sql`. Quarkus Flyway will detect it on startup and will proceed to create the Quartz database tables.

4. Configure the Camel Quartz component to use the Quarkus Quartz scheduler.
+
[source,java]
----
@Produces
@Singleton
@Named("quartz")
public QuartzComponent quartzComponent(Scheduler scheduler) {
QuartzComponent component = new QuartzComponent();
component.setScheduler(scheduler);
return component;
}
----

Quartz's property `org.quartz.jobStore.useProperties` is set to `true` and can not be modified. The value is forced by the Quarkus Quartz extension.
See the Quartz documentation for more information about `org.quartz.jobStore.useProperties`.
Further customization of the Quartz scheduler can be done via various configuration properties. Refer to to the https://quarkus.io/guides/quartz#quartz-configuration-reference[Quarkus Quartz Configuration] guide for more information.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ class QuartzProcessor {
"org.quartz.impl.jdbcjobstore.JobStoreSupport",
"org.quartz.impl.triggers.SimpleTriggerImpl",
"org.quartz.impl.triggers.AbstractTrigger",
"org.apache.camel.quarkus.component.quartz.CamelQuarkusQuartzConnectionProvider"
};
private static final DotName SQL_JDBC_DELEGATE = DotName.createSimple(StdJDBCDelegate.class.getName());

Expand Down Expand Up @@ -85,17 +84,15 @@ void registerForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveCla
.toArray(String[]::new);

reflectiveClasses.produce(new ReflectiveClassBuildItem(false, true, delegatesImpl));

}

@BuildStep
void indexSaxonHe(BuildProducer<IndexDependencyBuildItem> deps) {
deps.produce(new IndexDependencyBuildItem("org.quartz-scheduler", "quartz"));
void indexDependencies(BuildProducer<IndexDependencyBuildItem> indexedDependency) {
indexedDependency.produce(new IndexDependencyBuildItem("org.quartz-scheduler", "quartz"));
}

@BuildStep
NativeImageSystemPropertyBuildItem disableJMX() {

return new NativeImageSystemPropertyBuildItem("com.mchange.v2.c3p0.management.ManagementCoordinator",
"com.mchange.v2.c3p0.management.NullManagementCoordinator");
}
Expand Down
5 changes: 0 additions & 5 deletions extensions/quartz/runtime/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-quartz</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>svm</artifactId>
Expand Down
4 changes: 0 additions & 4 deletions extensions/quartz/runtime/src/main/doc/limitations.adoc

This file was deleted.

114 changes: 66 additions & 48 deletions extensions/quartz/runtime/src/main/doc/usage.adoc
Original file line number Diff line number Diff line change
@@ -1,55 +1,73 @@
=== Clustering

There are two options how to run Quartz in clustered mode:

==== Quarkus based

This is the preferred option. Follow the https://quarkus.io/guides/quartz[scheduling periodic tasks quartz guide].

- Define database configuration in `application.properties`.
- Use for example `flyway` to create database tables required for `Quartz`.

===== Quartz based with an Agroal datasource

Follow the http://www.quartz-scheduler.org/documentation/quartz-1.8.6/configuration/ConfigJDBCJobStoreClustering.html#configure-clustering-with-jdbc-jobstore[Configure Clustering with JDBC-JobStore Guide] with different DS configuration:

- Declare to use `io.quarkus:quarkus-agroal` in `pom.xml` explicitly.

```
Support for Quartz clustering is provided by the Quarkus Quartz extension. The follow steps outline how to configure Quarkus Quartz for use with Camel.

1. Enable Quartz clustered mode and configure a `DataSource` as a persistence Quartz job store. An example configuration is as follows.
+
[source,properties]
----
# Quartz configuration
quarkus.quartz.clustered=true
quarkus.quartz.store-type=jdbc-cmt
quarkus.quartz.start-mode=forced
# Datasource configuration
quarkus.datasource.db-kind=postgresql
quarkus.datasource.username=quarkus_test
quarkus.datasource.password=quarkus_test
quarkus.datasource.jdbc.url=jdbc:postgresql://localhost/quarkus_test

# Optional automatic creation of Quartz tables
quarkus.flyway.connect-retries=10
quarkus.flyway.table=flyway_quarkus_history
quarkus.flyway.migrate-at-start=true
quarkus.flyway.baseline-on-migrate=true
quarkus.flyway.baseline-version=1.0
quarkus.flyway.baseline-description=Quartz
----

2. Add the correct JDBC driver extension to your application that corresponds to the value of `quarkus.datasource.db-kind`. In the above
example `postgresql` is used, therefore the following JDBC dependency would be required. Adjust as necessary for your needs. Agroal is also required
for `DataSource` support.
+
[source,xml]
----
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-postgresql</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-agroal</artifactId>
</dependency>
```

- Use `quartz.properties` to configure the `JobStore`.
- Define a datasource via quarkus (see the https://quarkus.io/guides/datasource[Quarkus datasource documentation)] and use `CamelQuarkusQuartzConnectionProvider` as the `ConnectionProvider` in `quartz.properties`:
----
```
...
org.quartz.jobStore.dataSource = myDS

# datasource configuration
org.quartz.dataSource.myDS.connectionProvider.class = org.apache.camel.quarkus.component.quartz.CamelQuarkusQuartzConnectionProvider
org.quartz.dataSource.myDSB.dataSourceName = ds_name_if_not_set_default_ds_will_be_used
```


- You can use for example `flyway` to create database tables required for `Quartz`.

===== Quartz based

You can follow the http://www.quartz-scheduler.org/documentation/quartz-1.8.6/configuration/ConfigJDBCJobStoreClustering.html#configure-clustering-with-jdbc-jobstore[Configure Clustering with JDBC-JobStore Guide] without any modification:

```
...
org.quartz.jobStore.dataSource = myDS

# datasource configuration
org.quartz.dataSource.myDS.driver = org.postgresql.Driver

# datasource configuration
org.quartz.dataSource.myDS.URL=jdbc:postgresql://localhost:5432/default
org.quartz.dataSource.myDS.user = quarkus
org.quartz.dataSource.myDS.password = quarkus
```
3. https://quarkus.io/guides/flyway[Quarkus Flyway] can automatically create the necessary Quartz database tables for you. Add `quarkus-flyway` to your application (optional).
+
[source,xml]
----
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-flyway</artifactId>
</dependency>
----
+
Also add a Quartz database creation script for your chosen database kind.
The Quartz project provides ready made scripts that can be copied from https://github.com/quartz-scheduler/quartz/tree/master/quartz-core/src/main/resources/org/quartz/impl/jdbcjobstore[here]. Add the SQL
script to `src/main/resources/db/migration/V1.0.0__QuarkusQuartz.sql`. Quarkus Flyway will detect it on startup and will proceed to create the Quartz database tables.
4. Configure the Camel Quartz component to use the Quarkus Quartz scheduler.
+
[source,java]
----
@Produces
@Singleton
@Named("quartz")
public QuartzComponent quartzComponent(Scheduler scheduler) {
QuartzComponent component = new QuartzComponent();
component.setScheduler(scheduler);
return component;
}
----
Further customization of the Quartz scheduler can be done via various configuration properties. Refer to to the https://quarkus.io/guides/quartz#quartz-configuration-reference[Quarkus Quartz Configuration] guide for more information.

This file was deleted.

1 change: 1 addition & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@
<module>protobuf</module>
<module>pubnub</module>
<module>quartz</module>
<module>quartz-clustered</module>
<module>qute</module>
<module>rabbitmq</module>
<module>reactive-streams</module>
Expand Down

0 comments on commit a3e8105

Please sign in to comment.