You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/02/28 18:07:00 UTC

[camel] branch main updated: CAMEL-19060 (camel-seda): recreate the queue reference during restart

This is an automated email from the ASF dual-hosted git repository.

orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new b70584ddb35 CAMEL-19060 (camel-seda): recreate the queue reference during restart
b70584ddb35 is described below

commit b70584ddb3545a87acc1732f0e89b9cea704c461
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Tue Feb 28 16:34:25 2023 +0100

    CAMEL-19060 (camel-seda): recreate the queue reference during restart
---
 .../apache/camel/component/seda/SedaEndpoint.java  | 29 ++++++++++++++--------
 .../seda/SedaRemoveRouteThenAddAgainTest.java      |  4 +--
 2 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java b/components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
index 296e67c0071..d3fba484761 100644
--- a/components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
+++ b/components/camel-seda/src/main/java/org/apache/camel/component/seda/SedaEndpoint.java
@@ -208,25 +208,29 @@ public class SedaEndpoint extends DefaultEndpoint implements AsyncEndpoint, Brow
         }
     }
 
-    @Override
-    public void start() {
-        super.start();
-
-        final String key = getComponent().getQueueKey(getEndpointUri());
-        if (ref == null) {
-            ref = getComponent().getQueueReference(key);
-        }
-    }
-
     /**
      * Gets the {@link QueueReference} for this endpoint.
      *
      * @return the reference, or <tt>null</tt> if no queue reference exists.
      */
     public QueueReference getQueueReference() {
+        if (ref == null) {
+            ref = tryQueueRefInit();
+        }
+
         return ref;
     }
 
+    private QueueReference tryQueueRefInit() {
+        final SedaComponent component = getComponent();
+        if (component != null) {
+            final String key = component.getQueueKey(getEndpointUri());
+            return component.getQueueReference(key);
+        }
+
+        return null;
+    }
+
     protected synchronized AsyncProcessor getConsumerMulticastProcessor() {
         if (!multicastStarted && consumerMulticastProcessor != null) {
             // only start it on-demand to avoid starting it during stopping
@@ -543,6 +547,8 @@ public class SedaEndpoint extends DefaultEndpoint implements AsyncEndpoint, Brow
         if (queue == null) {
             queue = getQueue();
         }
+
+        ref = tryQueueRefInit();
     }
 
     @Override
@@ -552,6 +558,8 @@ public class SedaEndpoint extends DefaultEndpoint implements AsyncEndpoint, Brow
         } else {
             LOG.debug("There is still active consumers.");
         }
+
+        ref = null;
     }
 
     @Override
@@ -583,6 +591,7 @@ public class SedaEndpoint extends DefaultEndpoint implements AsyncEndpoint, Brow
 
         // clear queue, as we are shutdown, so if re-created then the queue must be updated
         queue = null;
+        ref = null;
     }
 
 }
diff --git a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaRemoveRouteThenAddAgainTest.java b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaRemoveRouteThenAddAgainTest.java
index db0b3a9b97b..c6b9721b220 100644
--- a/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaRemoveRouteThenAddAgainTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/component/seda/SedaRemoveRouteThenAddAgainTest.java
@@ -19,11 +19,11 @@ package org.apache.camel.component.seda;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
-import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.RepeatedTest;
 
 public class SedaRemoveRouteThenAddAgainTest extends ContextTestSupport {
 
-    @Test
+    @RepeatedTest(5)
     public void testRemoveRouteAndThenAddAgain() throws Exception {
         MockEndpoint out = getMockEndpoint("mock:out");
         out.expectedMessageCount(1);