You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2022/10/20 06:43:11 UTC
[camel-quarkus] 02/02: Fix handling of quartz autowired scheduler
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch quarkus-main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 94767c1109cf066356e2f7733ee04f6671e72ba1
Author: JiriOndrusek <on...@gmail.com>
AuthorDate: Thu Sep 29 11:41:37 2022 +0200
Fix handling of quartz autowired scheduler
Fixes #4076
---
extensions/quartz/deployment/pom.xml | 6 ++
.../quartz/deployment/QuartzProcessor.java | 14 +++
.../QuartzNoQuarkusSchedulerAutowiredTest.java | 45 ++++++++++
.../quartz/deployment/QuartzNotAutowiredTest.java | 46 ++++++++++
.../QuartzQuarkusCustomSchedulerAutowiredTest.java | 59 ++++++++++++
...artzQuarkusSchedulerAmbiguousAutowiredTest.java | 54 +++++++++++
.../QuartzQuarkusSchedulerAutowiredTest.java | 46 ++++++++++
.../QuartzQuarkusSchedulerNotAutowiredTest.java | 46 ++++++++++
...lication-configuration-not-autowired.properties | 8 +-
...tion-quarkus-scheduler-not-autowired.properties | 7 +-
...ation-configuration-quartz-scheduler.properties | 8 +-
.../component/quartz/CamelQuartzRecorder.java | 100 +++++++++++++++++++++
.../src/main/resources/application.properties | 2 -
13 files changed, 419 insertions(+), 22 deletions(-)
diff --git a/extensions/quartz/deployment/pom.xml b/extensions/quartz/deployment/pom.xml
index d07381cc88..0925b7fcf2 100644
--- a/extensions/quartz/deployment/pom.xml
+++ b/extensions/quartz/deployment/pom.xml
@@ -48,6 +48,12 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-quartz</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-junit5-internal</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/extensions/quartz/deployment/src/main/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzProcessor.java b/extensions/quartz/deployment/src/main/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzProcessor.java
index 2271ea570d..fe02409a4b 100644
--- a/extensions/quartz/deployment/src/main/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzProcessor.java
+++ b/extensions/quartz/deployment/src/main/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzProcessor.java
@@ -19,6 +19,8 @@ package org.apache.camel.quarkus.component.quartz.deployment;
import io.quarkus.bootstrap.model.ApplicationModel;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
+import io.quarkus.deployment.annotations.ExecutionTime;
+import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.IndexDependencyBuildItem;
@@ -26,6 +28,9 @@ import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageSystemPropertyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.pkg.builditem.CurateOutcomeBuildItem;
+import org.apache.camel.component.quartz.QuartzComponent;
+import org.apache.camel.quarkus.component.quartz.CamelQuartzRecorder;
+import org.apache.camel.quarkus.core.deployment.spi.CamelBeanBuildItem;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;
import org.quartz.impl.jdbcjobstore.StdJDBCDelegate;
@@ -97,4 +102,13 @@ class QuartzProcessor {
"com.mchange.v2.c3p0.management.NullManagementCoordinator");
}
+ @Record(ExecutionTime.STATIC_INIT)
+ @BuildStep
+ CamelBeanBuildItem quartzComponent(CamelQuartzRecorder recorder) {
+ return new CamelBeanBuildItem(
+ "quartz",
+ QuartzComponent.class.getName(),
+ recorder.createQuartzComponent());
+ }
+
}
diff --git a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzNoQuarkusSchedulerAutowiredTest.java b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzNoQuarkusSchedulerAutowiredTest.java
new file mode 100644
index 0000000000..d772112331
--- /dev/null
+++ b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzNoQuarkusSchedulerAutowiredTest.java
@@ -0,0 +1,45 @@
+/*
+ * 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.deployment;
+
+import javax.inject.Inject;
+
+import io.quarkus.test.QuarkusUnitTest;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.quartz.QuartzComponent;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class QuartzNoQuarkusSchedulerAutowiredTest {
+
+ @RegisterExtension
+ static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
+ .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
+
+ @Inject
+ CamelContext context;
+
+ @Test
+ public void test() throws Exception {
+ QuartzComponent component = context.getComponent("quartz", QuartzComponent.class);
+ assertEquals("DefaultQuartzScheduler-camel-1", component.getScheduler().getSchedulerName());
+ }
+}
diff --git a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzNotAutowiredTest.java b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzNotAutowiredTest.java
new file mode 100644
index 0000000000..a27f35727c
--- /dev/null
+++ b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzNotAutowiredTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.deployment;
+
+import javax.inject.Inject;
+
+import io.quarkus.test.QuarkusUnitTest;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.quartz.QuartzComponent;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class QuartzNotAutowiredTest {
+
+ @RegisterExtension
+ static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
+ .withConfigurationResource("application-configuration-not-autowired.properties")
+ .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
+
+ @Inject
+ CamelContext context;
+
+ @Test
+ public void test() throws Exception {
+ QuartzComponent component = context.getComponent("quartz", QuartzComponent.class);
+ assertEquals("DefaultQuartzScheduler-camel-1", component.getScheduler().getSchedulerName());
+ }
+}
diff --git a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusCustomSchedulerAutowiredTest.java b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusCustomSchedulerAutowiredTest.java
new file mode 100644
index 0000000000..218790aee4
--- /dev/null
+++ b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusCustomSchedulerAutowiredTest.java
@@ -0,0 +1,59 @@
+/*
+ * 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.deployment;
+
+import java.util.Properties;
+
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+import io.quarkus.test.QuarkusUnitTest;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.quartz.QuartzComponent;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.impl.StdSchedulerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class QuartzQuarkusCustomSchedulerAutowiredTest {
+
+ @RegisterExtension
+ static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
+ .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
+
+ @Inject
+ CamelContext context;
+
+ @Test
+ public void test() throws Exception {
+ QuartzComponent component = context.getComponent("quartz", QuartzComponent.class);
+ assertEquals("customScheduler", component.getScheduler().getSchedulerName());
+ }
+
+ @Produces
+ public Scheduler produceScheduler() throws SchedulerException {
+ Properties prop = new Properties();
+ prop.setProperty("org.quartz.scheduler.instanceName", "customScheduler");
+ prop.setProperty("org.quartz.threadPool.threadCount", "2");
+ return new StdSchedulerFactory(prop).getScheduler();
+ }
+}
diff --git a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerAmbiguousAutowiredTest.java b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerAmbiguousAutowiredTest.java
new file mode 100644
index 0000000000..a6771425ba
--- /dev/null
+++ b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerAmbiguousAutowiredTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.deployment;
+
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+
+import io.quarkus.test.QuarkusUnitTest;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.quartz.QuartzComponent;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.quartz.impl.StdSchedulerFactory;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class QuartzQuarkusSchedulerAmbiguousAutowiredTest {
+
+ @RegisterExtension
+ static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
+ .withConfigurationResource("application-configuration-quartz-scheduler.properties")
+ .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
+
+ @Inject
+ CamelContext context;
+
+ @Test
+ public void test() {
+ assertThrows(RuntimeException.class, () -> context.getComponent("quartz", QuartzComponent.class));
+ }
+
+ @Produces
+ public Scheduler produceScheduler() throws SchedulerException {
+ return new StdSchedulerFactory().getScheduler();
+ }
+}
diff --git a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerAutowiredTest.java b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerAutowiredTest.java
new file mode 100644
index 0000000000..82584425cf
--- /dev/null
+++ b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerAutowiredTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.deployment;
+
+import javax.inject.Inject;
+
+import io.quarkus.test.QuarkusUnitTest;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.quartz.QuartzComponent;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+public class QuartzQuarkusSchedulerAutowiredTest {
+
+ @RegisterExtension
+ static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
+ .withConfigurationResource("application-configuration-quartz-scheduler.properties")
+ .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
+
+ @Inject
+ CamelContext context;
+
+ @Test
+ public void test() throws Exception {
+ QuartzComponent component = context.getComponent("quartz", QuartzComponent.class);
+ assertEquals("QuarkusQuartzScheduler", component.getScheduler().getSchedulerName());
+ }
+}
diff --git a/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerNotAutowiredTest.java b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerNotAutowiredTest.java
new file mode 100644
index 0000000000..d402b91a6f
--- /dev/null
+++ b/extensions/quartz/deployment/src/test/java/org/apache/camel/quarkus/component/quartz/deployment/QuartzQuarkusSchedulerNotAutowiredTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.deployment;
+
+import javax.inject.Inject;
+
+import io.quarkus.test.QuarkusUnitTest;
+import org.apache.camel.CamelContext;
+import org.apache.camel.component.quartz.QuartzComponent;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+public class QuartzQuarkusSchedulerNotAutowiredTest {
+
+ @RegisterExtension
+ static final QuarkusUnitTest CONFIG = new QuarkusUnitTest()
+ .withConfigurationResource("application-configuration-quarkus-scheduler-not-autowired.properties")
+ .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
+
+ @Inject
+ CamelContext context;
+
+ @Test
+ public void test() throws Exception {
+ QuartzComponent component = context.getComponent("quartz", QuartzComponent.class);
+ assertEquals("DefaultQuartzScheduler-camel-1", component.getScheduler().getSchedulerName());
+ }
+}
diff --git a/integration-tests/quartz/src/main/resources/application.properties b/extensions/quartz/deployment/src/test/resources/application-configuration-not-autowired.properties
similarity index 78%
copy from integration-tests/quartz/src/main/resources/application.properties
copy to extensions/quartz/deployment/src/test/resources/application-configuration-not-autowired.properties
index 5f4f4eae05..54cddcf948 100644
--- a/integration-tests/quartz/src/main/resources/application.properties
+++ b/extensions/quartz/deployment/src/test/resources/application-configuration-not-autowired.properties
@@ -14,10 +14,4 @@
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
-
-camel.component.quartzFromProperties.propertiesFile = quartz.properties
-
-quarkus.native.resources.includes = quartz.properties
-
-#quick workaround caused by https://issues.apache.org/jira/browse/CAMEL-18143
-camel.component.quartz.autowired-enabled = false
+camel.component.quartz.autowired-enabled = false
\ No newline at end of file
diff --git a/integration-tests/quartz/src/main/resources/application.properties b/extensions/quartz/deployment/src/test/resources/application-configuration-quarkus-scheduler-not-autowired.properties
similarity index 82%
copy from integration-tests/quartz/src/main/resources/application.properties
copy to extensions/quartz/deployment/src/test/resources/application-configuration-quarkus-scheduler-not-autowired.properties
index 5f4f4eae05..f581e04595 100644
--- a/integration-tests/quartz/src/main/resources/application.properties
+++ b/extensions/quartz/deployment/src/test/resources/application-configuration-quarkus-scheduler-not-autowired.properties
@@ -14,10 +14,5 @@
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
-
-camel.component.quartzFromProperties.propertiesFile = quartz.properties
-
-quarkus.native.resources.includes = quartz.properties
-
-#quick workaround caused by https://issues.apache.org/jira/browse/CAMEL-18143
camel.component.quartz.autowired-enabled = false
+quarkus.quartz.start-mode=forced
\ No newline at end of file
diff --git a/integration-tests/quartz/src/main/resources/application.properties b/extensions/quartz/deployment/src/test/resources/application-configuration-quartz-scheduler.properties
similarity index 78%
copy from integration-tests/quartz/src/main/resources/application.properties
copy to extensions/quartz/deployment/src/test/resources/application-configuration-quartz-scheduler.properties
index 5f4f4eae05..2473026451 100644
--- a/integration-tests/quartz/src/main/resources/application.properties
+++ b/extensions/quartz/deployment/src/test/resources/application-configuration-quartz-scheduler.properties
@@ -14,10 +14,4 @@
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
-
-camel.component.quartzFromProperties.propertiesFile = quartz.properties
-
-quarkus.native.resources.includes = quartz.properties
-
-#quick workaround caused by https://issues.apache.org/jira/browse/CAMEL-18143
-camel.component.quartz.autowired-enabled = false
+quarkus.quartz.start-mode=forced
\ No newline at end of file
diff --git a/extensions/quartz/runtime/src/main/java/org/apache/camel/quarkus/component/quartz/CamelQuartzRecorder.java b/extensions/quartz/runtime/src/main/java/org/apache/camel/quarkus/component/quartz/CamelQuartzRecorder.java
new file mode 100644
index 0000000000..19920e9027
--- /dev/null
+++ b/extensions/quartz/runtime/src/main/java/org/apache/camel/quarkus/component/quartz/CamelQuartzRecorder.java
@@ -0,0 +1,100 @@
+/*
+ * 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.util.LinkedList;
+import java.util.stream.Collectors;
+
+import javax.enterprise.inject.AmbiguousResolutionException;
+
+import io.quarkus.arc.Arc;
+import io.quarkus.arc.InjectableInstance;
+import io.quarkus.arc.InstanceHandle;
+import io.quarkus.quartz.QuartzScheduler;
+import io.quarkus.quartz.runtime.QuartzSchedulerImpl;
+import io.quarkus.runtime.RuntimeValue;
+import io.quarkus.runtime.annotations.Recorder;
+import org.apache.camel.component.quartz.QuartzComponent;
+import org.quartz.Scheduler;
+import org.quartz.SchedulerException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Recorder
+public class CamelQuartzRecorder {
+
+ public RuntimeValue<QuartzComponent> createQuartzComponent() {
+ return new RuntimeValue<>(new QuarkusQuartzComponent());
+ }
+
+ @org.apache.camel.spi.annotations.Component("quartz")
+ static class QuarkusQuartzComponent extends QuartzComponent {
+ private static final Logger LOG = LoggerFactory.getLogger(QuarkusQuartzComponent.class);
+
+ @Override
+ public boolean isAutowiredEnabled() {
+ //autowiring is executed via custom code in doStart method
+ return false;
+ }
+
+ @Override
+ protected void doStartScheduler() throws Exception {
+ //autowire scheduler before the start
+
+ //if autowiring is enabled, execute it here, because special approach because of Quarkus has to be applied
+ if (super.isAutowiredEnabled() && getCamelContext().isAutowiredEnabled()) {
+ InjectableInstance<Scheduler> schedulers = Arc.container().select(Scheduler.class);
+
+ LinkedList<Scheduler> foundSchedulers = new LinkedList<>();
+
+ for (InstanceHandle<Scheduler> handle : schedulers.handles()) {
+ //Scheduler may be null in several cases, which would cause an exception in traditional autowiring
+ //see https://github.com/quarkusio/quarkus/issues/27929 for more details
+ if (handle.getBean().getBeanClass().equals(QuartzSchedulerImpl.class)) {
+ Scheduler scheduler = Arc.container().select(QuartzScheduler.class).getHandle().get().getScheduler();
+ if (scheduler != null) {
+ //scheduler is added only if is not null
+ foundSchedulers.add(scheduler);
+ }
+ continue;
+ }
+ foundSchedulers.add(handle.get());
+ }
+
+ if (foundSchedulers.size() > 1) {
+ throw new AmbiguousResolutionException(String.format("Found %d org.quartz.Scheduler beans (%s).",
+ foundSchedulers.size(), foundSchedulers.stream().map(s -> {
+ try {
+ return s.getSchedulerName();
+ } catch (SchedulerException e) {
+ return "Scheduler name retrieval failed.";
+ }
+ }).collect(Collectors.joining(", "))));
+ } else if (!foundSchedulers.isEmpty()) {
+ if (LOG.isInfoEnabled()) {
+ LOG.info(
+ "Autowired property: scheduler on component: quartz as exactly one instance of type: {} found in the registry",
+ Scheduler.class.getName());
+ }
+ setScheduler(foundSchedulers.getFirst());
+ }
+ }
+
+ super.doStartScheduler();
+ }
+ }
+}
diff --git a/integration-tests/quartz/src/main/resources/application.properties b/integration-tests/quartz/src/main/resources/application.properties
index 5f4f4eae05..dfc162983b 100644
--- a/integration-tests/quartz/src/main/resources/application.properties
+++ b/integration-tests/quartz/src/main/resources/application.properties
@@ -19,5 +19,3 @@ camel.component.quartzFromProperties.propertiesFile = quartz.properties
quarkus.native.resources.includes = quartz.properties
-#quick workaround caused by https://issues.apache.org/jira/browse/CAMEL-18143
-camel.component.quartz.autowired-enabled = false