forked from apache/camel-quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa1642a
commit 571e7f0
Showing
19 changed files
with
951 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
=== JDBC Job Store | ||
|
||
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`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
=== 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: | ||
|
||
- Use `quartz.properties` to configure `JobStore`. | ||
- Define datasource via quarkus (see the https://quarkus.io/guides/datasource[Quarkus datasource documentation)] and use `CamelQuarkusQuartzConnectionProvider` as `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 | ||
``` |
66 changes: 66 additions & 0 deletions
66
.../java/org/apache/camel/quarkus/component/quartz/CamelQuarkusQuartzConnectionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.camel.quarkus.component.quartz; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
import io.agroal.api.AgroalDataSource; | ||
import io.quarkus.agroal.DataSource.DataSourceLiteral; | ||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.ArcContainer; | ||
import io.quarkus.arc.InstanceHandle; | ||
import org.quartz.utils.ConnectionProvider; | ||
|
||
public class CamelQuarkusQuartzConnectionProvider implements ConnectionProvider { | ||
private AgroalDataSource dataSource; | ||
private String dataSourceName; | ||
|
||
@Override | ||
public Connection getConnection() throws SQLException { | ||
return dataSource.getConnection(); | ||
} | ||
|
||
@Override | ||
public void shutdown() { | ||
// Do nothing as the connection will be closed inside the Agroal extension | ||
} | ||
|
||
@Override | ||
public void initialize() { | ||
final ArcContainer container = Arc.container(); | ||
final InstanceHandle<AgroalDataSource> instanceHandle; | ||
final boolean useDefaultDataSource = dataSourceName == null || "".equals(dataSourceName.trim()); | ||
if (useDefaultDataSource) { | ||
instanceHandle = container.instance(AgroalDataSource.class); | ||
} else { | ||
instanceHandle = container.instance(AgroalDataSource.class, new DataSourceLiteral(dataSourceName)); | ||
} | ||
if (instanceHandle.isAvailable()) { | ||
this.dataSource = instanceHandle.get(); | ||
} else { | ||
String message = String.format( | ||
"JDBC Store configured but '%s' datasource is missing. You can configure your datasource by following the guide available at: https://quarkus.io/guides/datasource", | ||
useDefaultDataSource ? "default" : dataSourceName); | ||
throw new IllegalStateException(message); | ||
} | ||
} | ||
|
||
public void setDataSourceName(String dataSourceName) { | ||
this.dataSourceName = dataSourceName; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.