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

davsclaus 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 d3ecd9b5788 CAMEL-22223: camel-core: Make it possible to set route 
group in route templates, so created routes belong to a given group
d3ecd9b5788 is described below

commit d3ecd9b578870df8896eb737dd2e22ad71bedea0
Author: Claus Ibsen <[email protected]>
AuthorDate: Wed Jul 9 13:46:54 2025 +0200

    CAMEL-22223: camel-core: Make it possible to set route group in route 
templates, so created routes belong to a given group
---
 .../camel/catalog/models/templatedRoute.json       |  7 ++-
 .../apache/camel/catalog/schemas/camel-spring.xsd  |  9 +++
 .../apache/camel/catalog/schemas/camel-xml-io.xsd  |  9 +++
 .../main/java/org/apache/camel/CamelContext.java   | 59 +++++++++++++++++
 .../camel/impl/engine/SimpleCamelContext.java      | 22 +++++++
 .../org/apache/camel/impl/DefaultCamelContext.java | 30 ++++++++-
 .../java/org/apache/camel/impl/DefaultModel.java   | 24 ++++---
 .../org/apache/camel/model/templatedRoute.json     |  7 ++-
 .../main/java/org/apache/camel/model/Model.java    |  9 ++-
 .../camel/model/TemplatedRouteDefinition.java      | 22 +++++++
 .../camel/main/MainTemplatedRouteGroupTest.java    | 73 ++++++++++++++++++++++
 .../java/org/apache/camel/xml/in/ModelParser.java  |  1 +
 .../java/org/apache/camel/xml/out/ModelWriter.java |  1 +
 .../org/apache/camel/yaml/out/ModelWriter.java     |  1 +
 14 files changed, 252 insertions(+), 22 deletions(-)

diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/templatedRoute.json
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/templatedRoute.json
index b3c0f06fbb9..35050043bbc 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/templatedRoute.json
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/models/templatedRoute.json
@@ -14,8 +14,9 @@
   "properties": {
     "routeTemplateRef": { "index": 0, "kind": "attribute", "displayName": 
"Route Template Ref", "group": "common", "required": true, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "Sets the id of the route template to use to 
build the route." },
     "routeId": { "index": 1, "kind": "attribute", "displayName": "Route Id", 
"group": "common", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Sets the id of the route built from the route template." },
-    "prefixId": { "index": 2, "kind": "attribute", "displayName": "Prefix Id", 
"group": "common", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Sets a prefix to use for all node ids (not route id)." },
-    "parameter": { "index": 3, "kind": "element", "displayName": "Parameter", 
"group": "common", "required": false, "type": "array", "javaType": 
"java.util.List<org.apache.camel.model.TemplatedRouteParameterDefinition>", 
"deprecated": false, "autowired": false, "secret": false, "description": "Adds 
an input parameter of the template to build the route" },
-    "bean": { "index": 4, "kind": "element", "displayName": "Bean", "group": 
"common", "required": false, "type": "array", "javaType": 
"java.util.List<org.apache.camel.model.BeanFactoryDefinition<org.apache.camel.model.TemplatedRouteDefinition>>",
 "deprecated": false, "autowired": false, "secret": false, "description": "Adds 
a local bean as input of the template to build the route" }
+    "prefixId": { "index": 2, "kind": "attribute", "displayName": "Prefix Id", 
"group": "advanced", "label": "advanced", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "Sets a prefix to use for all node ids (not 
route id)." },
+    "group": { "index": 3, "kind": "attribute", "displayName": "Group", 
"group": "advanced", "label": "advanced", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The group name for the route built from this 
template. Multiple routes can belong to the same group." },
+    "parameter": { "index": 4, "kind": "element", "displayName": "Parameter", 
"group": "common", "required": false, "type": "array", "javaType": 
"java.util.List<org.apache.camel.model.TemplatedRouteParameterDefinition>", 
"deprecated": false, "autowired": false, "secret": false, "description": "Adds 
an input parameter of the template to build the route" },
+    "bean": { "index": 5, "kind": "element", "displayName": "Bean", "group": 
"common", "required": false, "type": "array", "javaType": 
"java.util.List<org.apache.camel.model.BeanFactoryDefinition<org.apache.camel.model.TemplatedRouteDefinition>>",
 "deprecated": false, "autowired": false, "secret": false, "description": "Adds 
a local bean as input of the template to build the route" }
   }
 }
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
index e8bedaecfa4..ca682973af6 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
@@ -13980,6 +13980,15 @@ Sets the id of the route built from the route template.
         <xs:documentation xml:lang="en">
 <![CDATA[
 Sets a prefix to use for all node ids (not route id).
+]]>
+        </xs:documentation>
+      </xs:annotation>
+    </xs:attribute>
+    <xs:attribute name="group" type="xs:string">
+      <xs:annotation>
+        <xs:documentation xml:lang="en">
+<![CDATA[
+The group name for the route built from this template. Multiple routes can 
belong to the same group.
 ]]>
         </xs:documentation>
       </xs:annotation>
diff --git 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
index 270ad8b292c..8dca4d09661 100644
--- 
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
+++ 
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-xml-io.xsd
@@ -12674,6 +12674,15 @@ Sets the id of the route built from the route template.
         <xs:documentation xml:lang="en">
 <![CDATA[
 Sets a prefix to use for all node ids (not route id).
+]]>
+        </xs:documentation>
+      </xs:annotation>
+    </xs:attribute>
+    <xs:attribute name="group" type="xs:string">
+      <xs:annotation>
+        <xs:documentation xml:lang="en">
+<![CDATA[
+The group name for the route built from this template. Multiple routes can 
belong to the same group.
 ]]>
         </xs:documentation>
       </xs:annotation>
diff --git a/core/camel-api/src/main/java/org/apache/camel/CamelContext.java 
b/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
index 7d41a6766d2..91d185cf062 100644
--- a/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
+++ b/core/camel-api/src/main/java/org/apache/camel/CamelContext.java
@@ -641,11 +641,31 @@ public interface CamelContext extends 
CamelContextLifecycle, RuntimeConfiguratio
      * @return                 the id of the route added (for example when an 
id was auto assigned)
      * @throws Exception       is thrown if error creating and adding the new 
route
      */
+    @Deprecated(since = "4.14.0")
     String addRouteFromTemplate(
             String routeId, String routeTemplateId, String prefixId,
             Map<String, Object> parameters)
             throws Exception;
 
+    /**
+     * Adds a new route from a given route template.
+     *
+     * Camel end users should favour using {@link 
org.apache.camel.builder.TemplatedRouteBuilder} which is a fluent
+     * builder with more functionality than this API.
+     *
+     * @param  routeId         the id of the new route to add (optional)
+     * @param  routeTemplateId the id of the route template (mandatory)
+     * @param  prefixId        prefix to use for all node ids (not route id). 
Use null for no prefix. (optional)
+     * @param  group           route group name (optional)
+     * @param  parameters      parameters to use for the route template when 
creating the new route
+     * @return                 the id of the route added (for example when an 
id was auto assigned)
+     * @throws Exception       is thrown if error creating and adding the new 
route
+     */
+    String addRouteFromTemplate(
+            String routeId, String routeTemplateId, String prefixId, String 
group,
+            Map<String, Object> parameters)
+            throws Exception;
+
     /**
      * Adds a new route from a given route template.
      *
@@ -659,10 +679,29 @@ public interface CamelContext extends 
CamelContextLifecycle, RuntimeConfiguratio
      * @return                      the id of the route added (for example 
when an id was auto assigned)
      * @throws Exception            is thrown if error creating and adding the 
new route
      */
+    @Deprecated(since = "4.14.0")
     String addRouteFromTemplate(
             String routeId, String routeTemplateId, String prefixId, 
RouteTemplateContext routeTemplateContext)
             throws Exception;
 
+    /**
+     * Adds a new route from a given route template.
+     *
+     * Camel end users should favour using {@link 
org.apache.camel.builder.TemplatedRouteBuilder} which is a fluent
+     * builder with more functionality than this API.
+     *
+     * @param  routeId              the id of the new route to add (optional)
+     * @param  routeTemplateId      the id of the route template (mandatory)
+     * @param  prefixId             prefix to use for all node ids (not route 
id). Use null for no prefix. (optional)
+     * @param  group                route group name (optional)
+     * @param  routeTemplateContext the route template context (mandatory)
+     * @return                      the id of the route added (for example 
when an id was auto assigned)
+     * @throws Exception            is thrown if error creating and adding the 
new route
+     */
+    String addRouteFromTemplate(
+            String routeId, String routeTemplateId, String prefixId, String 
group, RouteTemplateContext routeTemplateContext)
+            throws Exception;
+
     /**
      * Adds a new route from a given kamelet
      *
@@ -675,12 +714,32 @@ public interface CamelContext extends 
CamelContextLifecycle, RuntimeConfiguratio
      * @return                   the id of the route added (for example when 
an id was auto assigned)
      * @throws Exception         is thrown if error creating and adding the 
new route
      */
+    @Deprecated(since = "4.14.0")
     String addRouteFromKamelet(
             String routeId, String routeTemplateId, String prefixId,
             String parentRouteId, String parentProcessorId,
             Map<String, Object> parameters)
             throws Exception;
 
+    /**
+     * Adds a new route from a given kamelet
+     *
+     * @param  routeId           the id of the new route to add (optional)
+     * @param  routeTemplateId   the id of the kamelet route template 
(mandatory)
+     * @param  prefixId          prefix to use for all node ids (not route 
id). Use null for no prefix. (optional)
+     * @param  group             route group name (optional)
+     * @param  parentRouteId     the id of the route which is using the 
kamelet (such as from / to)
+     * @param  parentProcessorId the id of the processor which is using the 
kamelet (such as to)
+     * @param  parameters        parameters to use for the route template when 
creating the new route
+     * @return                   the id of the route added (for example when 
an id was auto assigned)
+     * @throws Exception         is thrown if error creating and adding the 
new route
+     */
+    String addRouteFromKamelet(
+            String routeId, String routeTemplateId, String prefixId, String 
group,
+            String parentRouteId, String parentProcessorId,
+            Map<String, Object> parameters)
+            throws Exception;
+
     /**
      * Removes the route templates matching the pattern
      *
diff --git 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SimpleCamelContext.java
 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SimpleCamelContext.java
index 28a49861e99..5c7237038bd 100644
--- 
a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SimpleCamelContext.java
+++ 
b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/SimpleCamelContext.java
@@ -780,6 +780,20 @@ public class SimpleCamelContext extends 
AbstractCamelContext {
         throw new UnsupportedOperationException();
     }
 
+    @Override
+    public String addRouteFromTemplate(
+            String routeId, String routeTemplateId, String prefixId, String 
group, Map<String, Object> parameters)
+            throws Exception {
+        throw new UnsupportedOperationException();
+    }
+
+    @Override
+    public String addRouteFromTemplate(
+            String routeId, String routeTemplateId, String prefixId, String 
group, RouteTemplateContext routeTemplateContext)
+            throws Exception {
+        throw new UnsupportedOperationException();
+    }
+
     @Override
     public String addRouteFromTemplate(
             String routeId, String routeTemplateId, String prefixId, 
RouteTemplateContext routeTemplateContext)
@@ -795,6 +809,14 @@ public class SimpleCamelContext extends 
AbstractCamelContext {
         throw new UnsupportedOperationException();
     }
 
+    @Override
+    public String addRouteFromKamelet(
+            String routeId, String routeTemplateId, String prefixId, String 
group, String parentRouteId,
+            String parentProcessorId, Map<String, Object> parameters)
+            throws Exception {
+        throw new UnsupportedOperationException();
+    }
+
     @Override
     public void removeRouteTemplates(String pattern) throws Exception {
         throw new UnsupportedOperationException();
diff --git 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index d83560182af..2a9ede673ad 100644
--- 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -359,14 +359,28 @@ public class DefaultCamelContext extends 
SimpleCamelContext implements ModelCame
     @Override
     public String addRouteFromTemplate(String routeId, String routeTemplateId, 
String prefixId, Map<String, Object> parameters)
             throws Exception {
-        return model.addRouteFromTemplate(routeId, routeTemplateId, prefixId, 
parameters);
+        return model.addRouteFromTemplate(routeId, routeTemplateId, prefixId, 
null, parameters);
+    }
+
+    @Override
+    public String addRouteFromTemplate(
+            String routeId, String routeTemplateId, String prefixId, String 
group, Map<String, Object> parameters)
+            throws Exception {
+        return model.addRouteFromTemplate(routeId, routeTemplateId, prefixId, 
group, parameters);
     }
 
     @Override
     public String addRouteFromTemplate(
             String routeId, String routeTemplateId, String prefixId, 
RouteTemplateContext routeTemplateContext)
             throws Exception {
-        return model.addRouteFromTemplate(routeId, routeTemplateId, prefixId, 
routeTemplateContext);
+        return model.addRouteFromTemplate(routeId, routeTemplateId, prefixId, 
null, routeTemplateContext);
+    }
+
+    @Override
+    public String addRouteFromTemplate(
+            String routeId, String routeTemplateId, String prefixId, String 
group, RouteTemplateContext routeTemplateContext)
+            throws Exception {
+        return model.addRouteFromTemplate(routeId, routeTemplateId, prefixId, 
group, routeTemplateContext);
     }
 
     @Override
@@ -374,7 +388,17 @@ public class DefaultCamelContext extends 
SimpleCamelContext implements ModelCame
             String routeId, String routeTemplateId, String prefixId,
             String parentRouteId, String parentProcessorId, Map<String, 
Object> parameters)
             throws Exception {
-        return model.addRouteFromKamelet(routeId, routeTemplateId, prefixId, 
parentRouteId, parentProcessorId, parameters);
+        return model.addRouteFromKamelet(routeId, routeTemplateId, prefixId, 
null, parentRouteId, parentProcessorId,
+                parameters);
+    }
+
+    @Override
+    public String addRouteFromKamelet(
+            String routeId, String routeTemplateId, String prefixId, String 
group, String parentRouteId,
+            String parentProcessorId, Map<String, Object> parameters)
+            throws Exception {
+        return model.addRouteFromKamelet(routeId, routeTemplateId, prefixId, 
group, parentRouteId, parentProcessorId,
+                parameters);
     }
 
     @Override
diff --git 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
index b457f31322e..db35220a395 100644
--- 
a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
+++ 
b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultModel.java
@@ -412,46 +412,47 @@ public class DefaultModel implements Model {
         if (parameters != null) {
             parameters.forEach(rtc::setParameter);
         }
-        return addRouteFromTemplate(routeId, routeTemplateId, null, rtc);
+        return addRouteFromTemplate(routeId, routeTemplateId, null, null, rtc);
     }
 
     @Override
-    public String addRouteFromTemplate(String routeId, String routeTemplateId, 
String prefixId, Map<String, Object> parameters)
+    public String addRouteFromTemplate(
+            String routeId, String routeTemplateId, String prefixId, String 
group, Map<String, Object> parameters)
             throws Exception {
         RouteTemplateContext rtc = new 
DefaultRouteTemplateContext(camelContext);
         if (parameters != null) {
             parameters.forEach(rtc::setParameter);
         }
-        return addRouteFromTemplate(routeId, routeTemplateId, prefixId, rtc);
+        return addRouteFromTemplate(routeId, routeTemplateId, prefixId, group, 
rtc);
     }
 
     public String addRouteFromTemplate(String routeId, String routeTemplateId, 
RouteTemplateContext routeTemplateContext)
             throws Exception {
-        return addRouteFromTemplate(routeId, routeTemplateId, null, 
routeTemplateContext);
+        return addRouteFromTemplate(routeId, routeTemplateId, null, null, 
routeTemplateContext);
     }
 
     @Override
     public String addRouteFromTemplate(
-            String routeId, String routeTemplateId, String prefixId,
+            String routeId, String routeTemplateId, String prefixId, String 
group,
             RouteTemplateContext routeTemplateContext)
             throws Exception {
-        return doAddRouteFromTemplate(routeId, routeTemplateId, prefixId, 
null, null, routeTemplateContext);
+        return doAddRouteFromTemplate(routeId, routeTemplateId, prefixId, 
group, null, null, routeTemplateContext);
     }
 
     @Override
     public String addRouteFromKamelet(
-            String routeId, String routeTemplateId, String prefixId,
+            String routeId, String routeTemplateId, String prefixId, String 
group,
             String parentRouteId, String parentProcessorId, Map<String, 
Object> parameters)
             throws Exception {
         RouteTemplateContext rtc = new 
DefaultRouteTemplateContext(camelContext);
         if (parameters != null) {
             parameters.forEach(rtc::setParameter);
         }
-        return doAddRouteFromTemplate(routeId, routeTemplateId, prefixId, 
parentRouteId, parentProcessorId, rtc);
+        return doAddRouteFromTemplate(routeId, routeTemplateId, prefixId, 
group, parentRouteId, parentProcessorId, rtc);
     }
 
     protected String doAddRouteFromTemplate(
-            String routeId, String routeTemplateId, String prefixId,
+            String routeId, String routeTemplateId, String prefixId, String 
group,
             String parentRouteId, String parentProcessorId,
             RouteTemplateContext routeTemplateContext)
             throws Exception {
@@ -555,6 +556,9 @@ public class DefaultModel implements Model {
         if (prefixId != null) {
             def.setNodePrefixId(prefixId);
         }
+        if (group != null) {
+            def.setGroup(group);
+        }
         def.setTemplateParameters(prop);
         def.setTemplateDefaultParameters(propDefaultValues);
         def.setRouteTemplateContext(routeTemplateContext);
@@ -626,7 +630,7 @@ public class DefaultModel implements Model {
         }
         // Add the route
         addRouteFromTemplate(templatedRouteDefinition.getRouteId(), 
templatedRouteDefinition.getRouteTemplateRef(),
-                templatedRouteDefinition.getPrefixId(), routeTemplateContext);
+                templatedRouteDefinition.getPrefixId(), 
templatedRouteDefinition.getGroup(), routeTemplateContext);
     }
 
     private RouteTemplateContext 
toRouteTemplateContext(TemplatedRouteDefinition templatedRouteDefinition) {
diff --git 
a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/templatedRoute.json
 
b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/templatedRoute.json
index b3c0f06fbb9..35050043bbc 100644
--- 
a/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/templatedRoute.json
+++ 
b/core/camel-core-model/src/generated/resources/META-INF/org/apache/camel/model/templatedRoute.json
@@ -14,8 +14,9 @@
   "properties": {
     "routeTemplateRef": { "index": 0, "kind": "attribute", "displayName": 
"Route Template Ref", "group": "common", "required": true, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "Sets the id of the route template to use to 
build the route." },
     "routeId": { "index": 1, "kind": "attribute", "displayName": "Route Id", 
"group": "common", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Sets the id of the route built from the route template." },
-    "prefixId": { "index": 2, "kind": "attribute", "displayName": "Prefix Id", 
"group": "common", "required": false, "type": "string", "javaType": 
"java.lang.String", "deprecated": false, "autowired": false, "secret": false, 
"description": "Sets a prefix to use for all node ids (not route id)." },
-    "parameter": { "index": 3, "kind": "element", "displayName": "Parameter", 
"group": "common", "required": false, "type": "array", "javaType": 
"java.util.List<org.apache.camel.model.TemplatedRouteParameterDefinition>", 
"deprecated": false, "autowired": false, "secret": false, "description": "Adds 
an input parameter of the template to build the route" },
-    "bean": { "index": 4, "kind": "element", "displayName": "Bean", "group": 
"common", "required": false, "type": "array", "javaType": 
"java.util.List<org.apache.camel.model.BeanFactoryDefinition<org.apache.camel.model.TemplatedRouteDefinition>>",
 "deprecated": false, "autowired": false, "secret": false, "description": "Adds 
a local bean as input of the template to build the route" }
+    "prefixId": { "index": 2, "kind": "attribute", "displayName": "Prefix Id", 
"group": "advanced", "label": "advanced", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "Sets a prefix to use for all node ids (not 
route id)." },
+    "group": { "index": 3, "kind": "attribute", "displayName": "Group", 
"group": "advanced", "label": "advanced", "required": false, "type": "string", 
"javaType": "java.lang.String", "deprecated": false, "autowired": false, 
"secret": false, "description": "The group name for the route built from this 
template. Multiple routes can belong to the same group." },
+    "parameter": { "index": 4, "kind": "element", "displayName": "Parameter", 
"group": "common", "required": false, "type": "array", "javaType": 
"java.util.List<org.apache.camel.model.TemplatedRouteParameterDefinition>", 
"deprecated": false, "autowired": false, "secret": false, "description": "Adds 
an input parameter of the template to build the route" },
+    "bean": { "index": 5, "kind": "element", "displayName": "Bean", "group": 
"common", "required": false, "type": "array", "javaType": 
"java.util.List<org.apache.camel.model.BeanFactoryDefinition<org.apache.camel.model.TemplatedRouteDefinition>>",
 "deprecated": false, "autowired": false, "secret": false, "description": "Adds 
a local bean as input of the template to build the route" }
   }
 }
diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/model/Model.java 
b/core/camel-core-model/src/main/java/org/apache/camel/model/Model.java
index f7b3b6c4a41..48a13b3fbfb 100644
--- a/core/camel-core-model/src/main/java/org/apache/camel/model/Model.java
+++ b/core/camel-core-model/src/main/java/org/apache/camel/model/Model.java
@@ -236,12 +236,13 @@ public interface Model {
      * @param  routeId         the id of the new route to add (optional)
      * @param  routeTemplateId the id of the route template (mandatory)
      * @param  prefixId        prefix to use when assigning route and node IDs 
(optional)
+     * @param  group           route group name (optional)
      * @param  parameters      parameters to use for the route template when 
creating the new route
      * @return                 the id of the route added (for example when an 
id was auto assigned)
      * @throws Exception       is thrown if error creating and adding the new 
route
      */
     String addRouteFromTemplate(
-            String routeId, String routeTemplateId, String prefixId,
+            String routeId, String routeTemplateId, String prefixId, String 
group,
             Map<String, Object> parameters)
             throws Exception;
 
@@ -251,12 +252,13 @@ public interface Model {
      * @param  routeId              the id of the new route to add (optional)
      * @param  routeTemplateId      the id of the route template (mandatory)
      * @param  prefixId             prefix to use when assigning route and 
node IDs (optional)
+     * @param  group                route group name (optional)
      * @param  routeTemplateContext the route template context (mandatory)
      * @return                      the id of the route added (for example 
when an id was auto assigned)
      * @throws Exception            is thrown if error creating and adding the 
new route
      */
     String addRouteFromTemplate(
-            String routeId, String routeTemplateId, String prefixId,
+            String routeId, String routeTemplateId, String prefixId, String 
group,
             RouteTemplateContext routeTemplateContext)
             throws Exception;
 
@@ -266,6 +268,7 @@ public interface Model {
      * @param  routeId           the id of the new route to add (optional)
      * @param  routeTemplateId   the id of the kamelet route template 
(mandatory)
      * @param  prefixId          prefix to use when assigning route and node 
IDs (optional)
+     * @param  group             route group name (optional)
      * @param  parentRouteId     the id of the route which is using the 
kamelet (such as from / to)
      * @param  parentProcessorId the id of the processor which is using the 
kamelet (such as to)
      * @param  parameters        parameters to use for the route template when 
creating the new route
@@ -273,7 +276,7 @@ public interface Model {
      * @throws Exception         is thrown if error creating and adding the 
new route
      */
     String addRouteFromKamelet(
-            String routeId, String routeTemplateId, String prefixId,
+            String routeId, String routeTemplateId, String prefixId, String 
group,
             String parentRouteId, String parentProcessorId,
             Map<String, Object> parameters)
             throws Exception;
diff --git 
a/core/camel-core-model/src/main/java/org/apache/camel/model/TemplatedRouteDefinition.java
 
b/core/camel-core-model/src/main/java/org/apache/camel/model/TemplatedRouteDefinition.java
index f143e1c4c1e..dbec1987fc6 100644
--- 
a/core/camel-core-model/src/main/java/org/apache/camel/model/TemplatedRouteDefinition.java
+++ 
b/core/camel-core-model/src/main/java/org/apache/camel/model/TemplatedRouteDefinition.java
@@ -55,7 +55,11 @@ public class TemplatedRouteDefinition implements 
CamelContextAware, ResourceAwar
     @XmlAttribute
     private String routeId;
     @XmlAttribute
+    @Metadata(label = "advanced")
     private String prefixId;
+    @XmlAttribute
+    @Metadata(label = "advanced")
+    private String group;
     @XmlElement(name = "parameter")
     @Metadata(description = "Adds an input parameter of the template to build 
the route")
     private List<TemplatedRouteParameterDefinition> parameters;
@@ -103,6 +107,14 @@ public class TemplatedRouteDefinition implements 
CamelContextAware, ResourceAwar
         this.prefixId = prefixId;
     }
 
+    public String getGroup() {
+        return group;
+    }
+
+    public void setGroup(String group) {
+        this.group = group;
+    }
+
     @Override
     public CamelContext getCamelContext() {
         return camelContext;
@@ -294,6 +306,16 @@ public class TemplatedRouteDefinition implements 
CamelContextAware, ResourceAwar
         return this;
     }
 
+    /**
+     * The group name for the route built from this template. Multiple routes 
can belong to the same group.
+     *
+     * @param group the group name
+     */
+    public TemplatedRouteDefinition group(String group) {
+        setGroup(group);
+        return this;
+    }
+
     /**
      * Sets the id of the route built from the route template.
      *
diff --git 
a/core/camel-main/src/test/java/org/apache/camel/main/MainTemplatedRouteGroupTest.java
 
b/core/camel-main/src/test/java/org/apache/camel/main/MainTemplatedRouteGroupTest.java
new file mode 100644
index 00000000000..bae97a76792
--- /dev/null
+++ 
b/core/camel-main/src/test/java/org/apache/camel/main/MainTemplatedRouteGroupTest.java
@@ -0,0 +1,73 @@
+/*
+ * 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.main;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.builder.RouteBuilder;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class MainTemplatedRouteGroupTest {
+
+    @Test
+    void testMain() {
+        Main main = new Main();
+        main.configure().addRoutesBuilder(new RouteBuilder() {
+            @Override
+            public void configure() {
+                routeTemplate("myTemplate")
+                        .templateParameter("foo")
+                        .templateParameter("bar")
+                        .from("direct:{{foo}}")
+                        .choice()
+                        .when(header("foo"))
+                        .log("${body}").id("myLog")
+                        .otherwise()
+                        .to("mock:{{bar}}").id("end");
+
+                templatedRoute("myTemplate")
+                        .routeId("my-route")
+                        .group("cheese")
+                        .parameter("foo", "fooVal")
+                        .parameter("bar", "barVal");
+
+                templatedRoute("myTemplate")
+                        .routeId("my-route2")
+                        .group("cheese")
+                        .parameter("foo", "fooVal2")
+                        .parameter("bar", "barVal2");
+
+                templatedRoute("myTemplate")
+                        .routeId("my-route3")
+                        .group("cake")
+                        .parameter("foo", "fooVal3")
+                        .parameter("bar", "barVal3");
+            }
+        });
+
+        main.start();
+
+        CamelContext context = main.getCamelContext();
+        assertEquals(3, context.getRoutes().size());
+        assertEquals(2, context.getRoutesByGroup("cheese").size());
+        assertEquals(1, context.getRoutesByGroup("cake").size());
+
+        main.stop();
+    }
+
+}
diff --git 
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java 
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
index 87598cc4478..b20b14fdefd 100644
--- 
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
+++ 
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/in/ModelParser.java
@@ -1154,6 +1154,7 @@ public class ModelParser extends BaseParser {
     }
     protected TemplatedRouteDefinition doParseTemplatedRouteDefinition() 
throws IOException, XmlPullParserException {
         return doParse(new TemplatedRouteDefinition(), (def, key, val) -> 
switch (key) {
+                case "group": def.setGroup(val); yield true;
                 case "prefixId": def.setPrefixId(val); yield true;
                 case "routeId": def.setRouteId(val); yield true;
                 case "routeTemplateRef": def.setRouteTemplateRef(val); yield 
true;
diff --git 
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
 
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
index d5aa32b0426..233a8d93ae8 100644
--- 
a/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
+++ 
b/core/camel-xml-io/src/generated/java/org/apache/camel/xml/out/ModelWriter.java
@@ -1823,6 +1823,7 @@ public class ModelWriter extends BaseWriter {
         doWriteAttribute("routeId", def.getRouteId(), null);
         doWriteAttribute("routeTemplateRef", def.getRouteTemplateRef(), null);
         doWriteAttribute("prefixId", def.getPrefixId(), null);
+        doWriteAttribute("group", def.getGroup(), null);
         doWriteList(null, "bean", def.getBeans(), 
this::doWriteBeanFactoryDefinition);
         doWriteList(null, "parameter", def.getParameters(), 
this::doWriteTemplatedRouteParameterDefinition);
         endElement(name);
diff --git 
a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java
 
b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java
index a28d76d766b..bddc904100d 100644
--- 
a/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java
+++ 
b/core/camel-yaml-io/src/generated/java/org/apache/camel/yaml/out/ModelWriter.java
@@ -1823,6 +1823,7 @@ public class ModelWriter extends BaseWriter {
         doWriteAttribute("routeId", def.getRouteId(), null);
         doWriteAttribute("routeTemplateRef", def.getRouteTemplateRef(), null);
         doWriteAttribute("prefixId", def.getPrefixId(), null);
+        doWriteAttribute("group", def.getGroup(), null);
         doWriteList(null, "bean", def.getBeans(), 
this::doWriteBeanFactoryDefinition);
         doWriteList(null, "parameter", def.getParameters(), 
this::doWriteTemplatedRouteParameterDefinition);
         endElement(name);


Reply via email to