From a5d3f94224f81bfb6b1c2dcaa9348422ea2f2bb1 Mon Sep 17 00:00:00 2001 From: Zheng Feng Date: Tue, 21 Jan 2025 12:31:22 +0800 Subject: [PATCH] Fix #6922 to add a JMS Component customizer if Artemis JMS RA is availiable (#6923) --- .../jms/deployment/JmsProcessor.java | 16 ++++++++ .../component/jms/CamelJmsRecorder.java | 40 +++++++++++++++++++ .../messaging/it/MessagingCommonRoutes.java | 16 +------- 3 files changed, 57 insertions(+), 15 deletions(-) create mode 100644 extensions/jms/runtime/src/main/java/org/apache/camel/quarkus/component/jms/CamelJmsRecorder.java diff --git a/extensions/jms/deployment/src/main/java/org/apache/camel/quarkus/component/jms/deployment/JmsProcessor.java b/extensions/jms/deployment/src/main/java/org/apache/camel/quarkus/component/jms/deployment/JmsProcessor.java index d8de90780354..d18cc95026e9 100644 --- a/extensions/jms/deployment/src/main/java/org/apache/camel/quarkus/component/jms/deployment/JmsProcessor.java +++ b/extensions/jms/deployment/src/main/java/org/apache/camel/quarkus/component/jms/deployment/JmsProcessor.java @@ -16,8 +16,13 @@ */ package org.apache.camel.quarkus.component.jms.deployment; +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.FeatureBuildItem; +import org.apache.camel.quarkus.component.jms.CamelJmsRecorder; +import org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem; import org.apache.camel.quarkus.core.deployment.spi.CamelSerializationBuildItem; class JmsProcessor { @@ -33,4 +38,15 @@ FeatureBuildItem feature() { CamelSerializationBuildItem serialization() { return new CamelSerializationBuildItem(); } + + @BuildStep + @Record(ExecutionTime.STATIC_INIT) + void customizer(BuildProducer customizers, CamelJmsRecorder recorder) { + try { + Class.forName("org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl"); + customizers.produce(new CamelContextCustomizerBuildItem(recorder.createCamelJmsCustomizer())); + } catch (ClassNotFoundException e) { + // Only create the JMS component customizer if the ActiveMQ Artemis RA is available + } + } } diff --git a/extensions/jms/runtime/src/main/java/org/apache/camel/quarkus/component/jms/CamelJmsRecorder.java b/extensions/jms/runtime/src/main/java/org/apache/camel/quarkus/component/jms/CamelJmsRecorder.java new file mode 100644 index 000000000000..8bcccc90ac00 --- /dev/null +++ b/extensions/jms/runtime/src/main/java/org/apache/camel/quarkus/component/jms/CamelJmsRecorder.java @@ -0,0 +1,40 @@ +/* + * 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.jms; + +import io.quarkus.runtime.RuntimeValue; +import io.quarkus.runtime.annotations.Recorder; +import org.apache.camel.CamelContext; +import org.apache.camel.component.jms.JmsComponent; +import org.apache.camel.spi.CamelContextCustomizer; +import org.apache.camel.spi.ComponentCustomizer; + +@Recorder +public class CamelJmsRecorder { + public RuntimeValue createCamelJmsCustomizer() { + return new RuntimeValue<>(new CamelContextCustomizer() { + @Override + public void configure(CamelContext context) { + context.getRegistry().bind("jms-ra-customizer", ComponentCustomizer.forType(JmsComponent.class, component -> { + component.setCacheLevelName("CACHE_NONE"); + component.setServiceLocationEnabled(false); + })); + } + }); + } +} diff --git a/integration-tests-support/messaging/common/src/main/java/org/apache/camel/quarkus/component/messaging/it/MessagingCommonRoutes.java b/integration-tests-support/messaging/common/src/main/java/org/apache/camel/quarkus/component/messaging/it/MessagingCommonRoutes.java index 9ba283403162..084aa8b12d2d 100644 --- a/integration-tests-support/messaging/common/src/main/java/org/apache/camel/quarkus/component/messaging/it/MessagingCommonRoutes.java +++ b/integration-tests-support/messaging/common/src/main/java/org/apache/camel/quarkus/component/messaging/it/MessagingCommonRoutes.java @@ -41,12 +41,7 @@ public void configure() throws Exception { // The routes are later started in AbstractMessagingTest#beforeAll method camelContext.setAutoStartup(false); - String cacheLevel = ""; - if (isCacheLevelNone()) { - cacheLevel = "&cacheLevelName=CACHE_NONE"; - } - - fromF("%s:queue:testJmsMessageType?concurrentConsumers=5%s", componentScheme, cacheLevel) + fromF("%s:queue:testJmsMessageType?concurrentConsumers=5", componentScheme) .toF("%s:queue:testJmsMessageType2", componentScheme); String disableStreaming = ""; @@ -120,13 +115,4 @@ private boolean isDisableStreaming() { return false; } } - - private boolean isCacheLevelNone() { - try { - Class.forName("org.apache.activemq.artemis.ra.ActiveMQRAConnectionFactoryImpl"); - return !componentScheme.getScheme().startsWith("sjms"); - } catch (ClassNotFoundException e) { - return false; - } - } }