Prevent adding same route multiple times
@@ -16,6 +16,8 @@ import org.apache.camel.CamelContext;
import org.apache.camel.LoggingLevel;
import org.apache.camel.builder.PredicateBuilder;
import org.apache.camel.builder.RouteBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import won.protocol.message.processor.camel.WonCamelConstants;
import won.protocol.vocabulary.WONMSG;
@@ -28,6 +30,7 @@ import won.protocol.vocabulary.WONMSG;
* generate routes dynamically in runtime that listen to those queues.
*/
public class OwnerApplicationListenerRouteBuilder extends RouteBuilder {
+ private final Logger logger = LoggerFactory.getLogger(getClass());
private String endpoint;
private URI brokerUri;
@@ -48,6 +51,15 @@ public class OwnerApplicationListenerRouteBuilder extends RouteBuilder {
// name. Also, we're unsure if the concurrentConsumers part is even interpreted
// anywhere // from(endpoints.get(i)
// +"?concurrentConsumers=2")
+
+ synchronized(this) {
+ //we sometimes see the owner fail during startup because it's trying to add
+ //the same route multiple times here. That's why we added the synchronized block
+ //and this check if the route exists.
+ if (getContext().hasEndpoint(endpoint) != null) {
+ logger.debug("route for listening to remote queue {} already configured", endpoint);
+ return;
+ }
from(endpoint).routeId("Node2OwnerRoute" + brokerUri).to("bean:wonMessageIntoCamelProcessor")
.to("bean:wellformednessChecker").to("bean:uriNodePathChecker").choice()
.when(PredicateBuilder.or(
@@ -76,3 +88,4 @@ public class OwnerApplicationListenerRouteBuilder extends RouteBuilder {
.to("bean:mainOwnerMessageProcessor").end();
}
}
+}
