davsclaus commented on code in PR #25531: URL: https://github.com/apache/camel/pull/25531#discussion_r3843289939
########## components/camel-jms/src/test/java/org/apache/camel/component/jms/reply/TemporaryQueueReplyManagerRefreshTest.java: ########## @@ -0,0 +1,256 @@ +/* + * 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.component.jms.reply; + +import java.util.concurrent.atomic.AtomicInteger; + +import jakarta.jms.Connection; +import jakarta.jms.JMSException; +import jakarta.jms.Session; +import jakarta.jms.TemporaryQueue; + +import org.apache.camel.CamelContext; +import org.apache.camel.component.jms.JmsConfiguration; +import org.apache.camel.component.jms.JmsEndpoint; +import org.apache.camel.component.jms.TemporaryQueueResolver; +import org.apache.camel.test.infra.artemis.common.ConnectionFactoryHelper; +import org.apache.camel.test.infra.artemis.services.ArtemisService; +import org.apache.camel.test.infra.artemis.services.ArtemisServiceFactory; +import org.apache.camel.test.infra.core.DefaultCamelContextExtension; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class TemporaryQueueReplyManagerRefreshTest { + + @RegisterExtension + static DefaultCamelContextExtension contextExtension = new DefaultCamelContextExtension(); + + @RegisterExtension + static ArtemisService service = ArtemisServiceFactory.createVMService(); + + private TemporaryQueueReplyManager replyManager; + + @BeforeEach + void setUp() { Review Comment: None of the tests in this class start the `TemporaryQueueReplyManager` (no call to `.start()`/`doStart()`), so `listenerContainer` stays `null` throughout. That means `triggerReplyDestinationRecovery()` always hits its early `listenerContainer == null` guard, and `runReplyDestinationRecovery()` / `DefaultJmsMessageListenerContainer.recoverReplyDestinationAfterRefresh()` are never actually exercised by this test class. That background-recovery path is specifically what fixes Scenario A from the PR description ("cached consumer, no one left to call the destination resolver") — arguably the trickiest part of this fix — and it currently has no test coverage. The generation-counter tests here are valuable for Scenarios B/C, but could you add a test (or extend `JmsTemporaryReplyToRequestReplyIT`) that starts a real listener container, forces an `onException`/`scheduleRefresh()` while a consumer is already cached, and asserts recovery actually happens end-to-end? ########## components/camel-jms/src/main/java/org/apache/camel/component/jms/reply/TemporaryQueueReplyManager.java: ########## @@ -57,9 +63,95 @@ public TemporaryQueueReplyManager(CamelContext camelContext, TemporaryQueueResol @Override protected void doStop() throws Exception { super.doStop(); + if (refreshRecoveryExecutor != null) { + camelContext.getExecutorServiceManager().shutdownNow(refreshRecoveryExecutor); + refreshRecoveryExecutor = null; + } ServiceHelper.stopService(destinationResolver); } + private void triggerReplyDestinationRecovery() { + if (listenerContainer == null || isStopping() || isStopped()) { + return; + } + if (!destinationResolver.isRefreshPending()) { + return; + } + if (!refreshRecoveryScheduled.compareAndSet(false, true)) { + return; + } + try { + getRefreshRecoveryExecutor().execute(this::runReplyDestinationRecovery); + } catch (RejectedExecutionException e) { + refreshRecoveryScheduled.set(false); + } + } + + private void runReplyDestinationRecovery() { + try { + long delay = endpoint.getRecoveryInterval() >= 0 ? endpoint.getRecoveryInterval() : 5000L; + if (!sleepQuietly(delay)) { + return; + } + int attempts = 0; + while (destinationResolver.isRefreshPending() && !isStopping() && !isStopped() + && listenerContainer != null && listenerContainer.isRunning() && attempts < 20) { + try { + if (listenerContainer instanceof DefaultJmsMessageListenerContainer dmlc) { + if (dmlc.isRecovering()) { + if (!sleepQuietly(delay)) { + return; + } + attempts++; + continue; + } + dmlc.recoverReplyDestinationAfterRefresh(); Review Comment: Question/assumption for the author to confirm rather than a blocking issue: `TemporaryQueueReplyManager` uses a single shared `listenerContainer` (one temp queue) for *all* in-flight InOut exchanges on this endpoint. `DefaultMessageListenerContainer.recoverAfterListenerSetupFailure()` calls `refreshConnectionUntilSuccessful()`, which for a shared connection tears down and recreates the entire underlying JMS `Connection` (`refreshSharedConnection()` in Spring's `AbstractJmsListeningContainer`) — not just the one consumer whose replyTo needs refreshing. Since `triggerReplyDestinationRecovery()` is only invoked from the JMS `ExceptionListener` (i.e. after a genuine connection-level fault, which already affects every consumer on the shared connection), this is probably the right call — but could you confirm this blast radius was considered, particularly for `replyToConcurrentConsumers > 1` where multiple concurrent in-flight replies would be sharing this container? ########## core/camel-core-model/src/generated/resources/META-INF/services/org/apache/camel/model.properties: ########## @@ -13,11 +13,16 @@ beanFactory beanio bearerToken bindy +blacklistServiceFilter Review Comment: This generated file picks up ~23 unrelated entries (`blacklistServiceFilter`, `consulServiceDiscovery`, `kubernetesServiceDiscovery`, `zookeeperServiceDiscovery`, `serviceCall`, load-balancer configs, etc.) that have nothing to do with the JMS replyTo fix. This looks like a stale/partial local build state (e.g. a full reactor build picking up modules that weren't part of a scoped build) that leaked into the commit. `git log` on this file shows the same class of issue was reverted before in `ba216589e5ee` ("revert spurious generated file changes"). Please drop this file from the diff — it should regenerate to match `main` once the branch is rebased and only the affected module is rebuilt. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
