@@ -9,8 +9,8 @@ kind of use cases.
99
1010You associate a route with a given `RoutePolicy` and then during
1111runtime Camel will invoke callbacks on this policy where you can
12- implement your custom logic. Camel provides a support class that is a
13- good base class to extend `org.apache.camel.support.RoutePolicySupport`.
12+ implement your custom logic. Camel provides a support class that can be used
13+ to extend `org.apache.camel.support.RoutePolicySupport` and implement your logic .
1414
1515There are these callbacks invoked:
1616
@@ -40,12 +40,17 @@ fast.
4040based policy modeled after the circuit breaker. This policy will stop consuming
4141from an endpoint based on the type of exceptions that are thrown and the threshold setting.
4242
43+ * `org.apache.camel.impl.cluster.ClusteredRoutePolicy` - is the foundation for `camel-cluster`
44+ which handles Camel routes to become active if a node becomes leader in a cluster.
45+
4346Camel also provides an ability to schedule routes to
4447be activated, deactivated, suspended and/or resumed at certain times
4548during the day using a
4649xref:scheduledroutepolicy.adoc[ScheduledRoutePolicy] (offered via the
4750xref:components::quartz-component.adoc[Quartz] component).
4851
52+ And route policy is also used as an implementation details for some of the Camel observability components.
53+
4954== SuspendableService
5055
5156If you want to dynamic suspend/resume routes, then it is advised to
@@ -63,22 +68,11 @@ The throttling in flight route policy has the following options:
6368
6469[width="100%",cols="10%,10%,80%",options="header",]
6570|===
66-
6771|Option |Default |Description
68-
69- |`scope` |`Route` |A scope for either `Route` or `Context` which defines if the current
70- number of in flight exchanges is context based or for that particular
71- route.
72-
73- |`maxInflightExchanges` |`1000` |The maximum threshold when the throttling will start to suspend the
74- route if the current number of in flight exchanges is higher than this
75- value.
76-
77- |`resumePercentOfMax` |`70` |A percentage `0..100` which defines when the throttling should resume
78- again in case it has been suspended.
79-
72+ |`scope` |`Route` |A scope for either `Route` or `Context` which defines if the current number of in flight exchanges is context based or for that particular route.
73+ |`maxInflightExchanges` |`1000` |The maximum threshold when the throttling will start to suspend the route if the current number of in flight exchanges is higher than this value.
74+ |`resumePercentOfMax` |`70` |A percentage `0..100` which defines when the throttling should resume again in case it has been suspended.
8075|`loggingLevel` |`INFO` |The logging level used for logging the throttling activity.
81-
8276|`logger` |`ThrottlingInflightRoutePolicy` |The logger category.
8377|===
8478
@@ -101,84 +95,171 @@ messages per time unit.
10195
10296See xref:scheduledroutepolicy.adoc[Scheduled Route Policy] for scheduling based route policy.
10397
104- == Using route policies in Camel routes
98+ == Using RoutePolicy in Camel routes
99+
100+ On the route(s) that should use one or more route policies, you configure this as shown below:
105101
106- You configure the route policy as follows from Java DSL, using the
107- `routePolicy` method:
102+ [tabs]
103+ ====
108104
105+ Java::
106+ +
107+ You configure the route policy as follows from Java DSL, using the `routePolicy` method:
108+ +
109109[source,java]
110- -----------------------------------------------------------
110+ ----
111111RoutePolicy myPolicy = new MyRoutePolicy();
112112
113- from("seda:foo").routePolicy(myPolicy).to("mock:result");
114- -----------------------------------------------------------
115-
116- In Spring XML you configure using the `routePolictRef` attribute on `<route>` as shown:
113+ from("seda:foo")
114+ .routePolicy(myPolicy)
115+ .to("mock:result");
116+ ----
117117
118+ XML::
119+ +
120+ In XML you configure using the `routePolictRef` attribute on `<route>` as shown:
121+ +
118122[source,xml]
119- ---------------------------------------------------------
123+ ----
120124<bean id="myPolicy" class="com.mycompany.MyRoutePolicy"/>
121125
122126<route routePolicyRef="myPolicy">
123127 <from uri="seda:foo"/>
124128 <to uri="mock:result"/>
125129</route>
126- ---------------------------------------------------------
130+ ----
131+
132+ YAML::
133+ +
134+ In YAML you configure using the `routePolictRef` attribute on `route` node as shown:
135+ +
136+ [source,yaml]
137+ ----
138+ - route:
139+ routePolicyRef: myPolicy
140+ from:
141+ uri: seda:foo
142+ steps:
143+ - to:
144+ uri: mock:result
145+ ----
146+ ====
127147
128148You can configure one or more route policies (separated by comma), such as:
129149
150+ [tabs]
151+ ====
152+
153+ Java::
154+ +
130155[source,java]
131156----
132- from("seda:foo").routePolicy(myPolicy, myOtherPolicy).to("mock:result");
157+ from("seda:foo")
158+ .routePolicy(myPolicy, myOtherPolicy)
159+ .to("mock:result");
133160----
134161
135- And in XML:
136-
162+ XML: :
163+ +
137164[source,xml]
138- ---------------------------------------------------------
165+ ----
166+ <bean id="myPolicy" class="com.mycompany.MyRoutePolicy"/>
167+
139168<route routePolicyRef="myPolicy,myOtherPolicy">
140169 <from uri="seda:foo"/>
141170 <to uri="mock:result"/>
142171</route>
143- ---------------------------------------------------------
172+ ----
173+
174+ YAML::
175+ +
176+ [source,yaml]
177+ ----
178+ - route:
179+ routePolicyRef: myPolicy,myOtherPolicy
180+ from:
181+ uri: seda:foo
182+ steps:
183+ - to:
184+ uri: mock:result
185+ ----
186+ ====
187+
144188
145189== Using RoutePolicyFactory
146190
147191If you want to use a route policy for every route, you can use
148- a `org.apache.camel.spi.RoutePolicyFactory` as a factory for creating
149- a `RoutePolicy` instance for each route. This can be used when you
150- want to use the same kind of route policy for all or some routes .
192+ a `org.apache.camel.spi.RoutePolicyFactory` as a factory for creating new
193+ `RoutePolicy` instance(s) for each route. This can be used when you
194+ want to use the same kind of route policy for all.
151195
152196With the factory, you only need to configure this once, and every route created will
153197have the policy assigned.
154198
155199There is API on `CamelContext` to add a factory, as shown below
156200
201+ [tabs]
202+ ====
203+
204+ Java::
205+ +
157206[source,java]
158- ----------------------------------------------------------
207+ ----
208+ CamelContext context = ...
159209context.addRoutePolicyFactory(new MyRoutePolicyFactory());
160- ----------------------------------------------------------
161-
162- And from XML DSL you just define a `<bean>` with the factory, and Camel will automatically detect this factory:
210+ ----
163211
164- [source,xml]
165- ----------------------------------------------------------------------
166- <bean id="myRoutePolicyFactory" class="com.foo.MyRoutePolicyFactory"/>
167- ----------------------------------------------------------------------
212+ Spring Boot::
213+ +
214+ You can also mark your class with Spring Boot `@Component` for automatic dependency injection
215+ +
216+ [source,java]
217+ ----
218+ @Component
219+ public class MyRoutePolicyFactory() {
168220
169- You can have as many route policy factories as you want, so if you have two factories,
170- you can add them both as shown:
221+ }
222+ ----
171223
224+ Quarkus::
225+ +
226+ You can also mark your class with Quarkus `@.ApplicationScoped` for automatic dependency injection
227+ +
172228[source,java]
173- ----------------------------------------------------------
174- context.addRoutePolicyFactory(new MyRoutePolicyFactory());
175- context.addRoutePolicyFactory(new MyOtherRoutePolicyFactory());
176- ----------------------------------------------------------
229+ ----
230+ @ApplicationScoped
231+ public class MyRoutePolicyFactory() {
177232
178- And in XML:
233+ }
234+ ----
179235
236+
237+ Spring XML::
238+ +
239+ And from Spring XML DSL you just define a `<bean>` with the factory, and Camel will automatically detect this factory:
240+ +
180241[source,xml]
181- ----------------------------------------------------------------------
242+ ----
182243<bean id="myRoutePolicyFactory" class="com.foo.MyRoutePolicyFactory"/>
183- <bean id="myOtherRoutePolicyFactory" class="com.foo.MyOtherRoutePolicyFactory"/>
184- ----------------------------------------------------------------------
244+ ----
245+
246+ XML::
247+ +
248+ [source,xml]
249+ ----
250+ <bean name="myRoutePolicyFactory" type="com.foo.MyRoutePolicyFactory"/>
251+ ----
252+
253+ YAML::
254+ +
255+ [source,yaml]
256+ ----
257+ - beans:
258+ - name: myRoutePolicyFactory
259+ type: com.foo.MyRoutePolicyFactory
260+ ----
261+ ====
262+
263+ TIP: You can have as many route policy factories as you want, so if you have two factories,
264+ you can just add both of them.
265+
0 commit comments