Skip to content

Commit f32387f

Browse files
committed
CAMEL-16861: Update docs
1 parent 4951c9d commit f32387f

9 files changed

Lines changed: 227 additions & 144 deletions

File tree

docs/user-manual/modules/ROOT/pages/expression.adoc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ To support dynamic rules Camel supports pluggable
1010
https://www.javadoc.io/doc/org.apache.camel/camel-api/current/org/apache/camel/Expression.html[Expression]
1111
strategies using a variety of different xref:components:languages:index.adoc[Languages].
1212

13-
== Expression API
13+
NOTE: The xref:components:languages:simple-language.adoc[Simple] is often used as predicates and expressions
14+
with the Camel EIPs.
1415

1516
If you are outside the DSL and want to create your own
1617
expressions you can either implement the
@@ -19,7 +20,7 @@ interface], reuse one of the other builders or try the
1920
https://www.javadoc.io/doc/org.apache.camel/camel-support/current/org/apache/camel/support/builder/ExpressionBuilder.html[ExpressionBuilder
2021
class].
2122

22-
=== Expression
23+
== Expression API
2324

2425
The API for a Camel Expression is defined in the
2526
`org.apache.camel.Expression` interface as shown:
@@ -38,3 +39,5 @@ public interface Expression {
3839
}
3940
----
4041

42+
A `Expression` is being evaluated to an Object value. This makes expressions so
43+
powerful as this can be used for functions, data mapping, templating, and for low-code users.

docs/user-manual/modules/ROOT/pages/parameter-binding-annotations.adoc

Lines changed: 85 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,26 @@
22

33
The bean parameter binding annotations from Camel are as follows:
44

5-
[width="100%",cols="34%,33%,33%",options="header",]
6-
|=======================================================================
7-
|Annotation |Meaning |Parameter
8-
|`org.apache.camel.Body`
9-
|To bind to an inbound message body |
10-
11-
|`org.apache.camel.Header`
12-
|To bind to a message header |String name of the header
13-
14-
|`org.apache.camel.Headers`
15-
|To bind to the Map of the message headers |
16-
17-
|`org.apache.camel.Variable`
18-
|To bind to a named variable |String name of the
19-
variable
20-
21-
|`org.apache.camel.Variables`
22-
|To bind to the variables map |
23-
24-
|`org.apache.camel.ExchangeProperty`
25-
|To bind to a named property on the exchange |String name of the
26-
property
27-
28-
|`org.apache.camel.ExchangeProperties`
29-
|To bind to the exchange property map on the exchange |
30-
31-
|`org.apache.camel.ExchangeException`
32-
|To bind to an Exception set on the exchange |
33-
34-
|=======================================================================
5+
[width="100%",cols="1m,2",options="header",]
6+
|===
7+
|Annotation | Meaning
8+
|`org.apache.camel.Body` | To bind to an inbound message body
9+
|`org.apache.camel.Header` | To bind to a message header by the given name
10+
|`org.apache.camel.Headers` | To bind to the Map of the message headers
11+
|`org.apache.camel.Variable` | To bind to a named variable the given name
12+
|`org.apache.camel.Variables` | To bind to the variables map
13+
|`org.apache.camel.ExchangeProperty` | To bind to a named property on the exchange the given name
14+
|`org.apache.camel.ExchangeProperties` | To bind to the exchange property map on the exchange
15+
|`org.apache.camel.ExchangeException` | To bind to an Exception set on the exchange
16+
|===
3517

3618
These annotations can be used with the xref:components::bean-component.adoc[Bean]
3719
component or when invoking beans in the xref:dsl.adoc[DSL]
3820

3921
Annotations can be used to define an xref:expression.adoc[Expression] or
4022
to extract various headers, properties or payloads from a
41-
xref:components:eips:message.adoc[Message] when invoking a bean method (see
42-
xref:bean-integration.adoc[Bean Integration] for more detail of how to
43-
invoke bean methods) together with being useful to help disambiguate
44-
which method to invoke.
23+
xref:components:eips:message.adoc[Message] when invoking a bean method. See
24+
xref:bean-integration.adoc[Bean Integration] for more in depth details on invoking beans.
4525

4626
If no annotations are used then Camel assumes that a single parameter is
4727
the body of the message. Camel will then use the
@@ -78,11 +58,11 @@ TIP: You don't necessarily need to use the `@Consume` annotation if you don't
7858
want to as you could also make use of the Camel xref:dsl.adoc[DSL] to
7959
route to the bean's method as well.
8060

81-
=== Using the DSL to invoke the bean method
61+
=== Calling bean from Camel routes
8262

8363
Here is another example which does not use xref:pojo-consuming.adoc[POJO
8464
Consuming] annotations but instead uses the xref:dsl.adoc[DSL] to route
85-
messages to the bean method
65+
messages to the bean method.
8666

8767
[source,java]
8868
----
@@ -97,23 +77,79 @@ public class MyBean {
9777

9878
The routing DSL then looks like this
9979

80+
[tabs]
81+
====
82+
83+
Java::
84+
+
10085
[source,java]
10186
----
10287
from("activemq:someQueue").
10388
to("bean:myBean");
10489
----
10590
91+
XML::
92+
+
93+
[source,xml]
94+
----
95+
<route>
96+
<from uri="activemq:someQueue"/>
97+
<to uri="bean:myBean"/>
98+
</route>
99+
----
100+
101+
YAML::
102+
+
103+
[source,yaml]
104+
----
105+
- route:
106+
from:
107+
uri: activemq:someQueue
108+
steps:
109+
- to:
110+
uri: bean:myBean
111+
----
112+
====
113+
106114
Here *myBean* would be looked up in the xref:registry.adoc[Registry]
107115
then the body of the message would be used to try figure out what method to call.
108116

109117
If you want to be explicit you can use:
110118

119+
[tabs]
120+
====
121+
122+
Java::
123+
+
111124
[source,java]
112125
----
113126
from("activemq:someQueue").
114-
to("bean:myBean?methodName=doSomething");
127+
to("bean:myBean?method=doSomething");
128+
----
129+
130+
XML::
131+
+
132+
[source,xml]
133+
----
134+
<route>
135+
<from uri="activemq:someQueue"/>
136+
<to uri="bean:myBean?method=doSomething"/>
137+
</route>
115138
----
116139
140+
YAML::
141+
+
142+
[source,yaml]
143+
----
144+
- route:
145+
from:
146+
uri: activemq:someQueue
147+
steps:
148+
- to:
149+
uri: bean:myBean?method=doSomething
150+
----
151+
====
152+
117153
And here we have a nifty example for you to show some great power in
118154
Camel. You can mix and match the annotations with the normal parameters,
119155
so we can have this example with annotations and the Exchange also:
@@ -136,28 +172,16 @@ Camel to bind expressions to method parameters when using
136172
xref:bean-integration.adoc[Bean Integration]. For example, you can use
137173
any of these annotations:
138174

139-
[width="100%",cols="50%,50%",options="header",]
140-
|=======================================================================
175+
[width="100%",cols="1m,2",options="header",]
176+
|===
141177
|Annotation |Description
142-
|`@Bean`
143-
|Inject a xref:components:languages:bean-language.adoc[Bean] expression
144-
145-
|`@Constant`
146-
|Inject a xref:components:languages:constant-language.adoc[Constant] expression
147-
148-
|`@Groovy`
149-
|Inject a xref:components:languages:groovy-language.adoc[Groovy] expression
150-
151-
|`@Header`
152-
|Inject a xref:components:languages:header-language.adoc[Header] expression
153-
154-
|`@Simple`
155-
|Inject an xref:components:languages:simple-language.adoc[Simple] expression
156-
157-
|`@XPath`
158-
|Inject an xref:components:languages:xpath-language.adoc[XPath] expression
159-
160-
|=======================================================================
178+
|`@Bean`|Inject a xref:components:languages:bean-language.adoc[Bean] expression
179+
|`@Constant`|Inject a xref:components:languages:constant-language.adoc[Constant] expression
180+
|`@Groovy`|Inject a xref:components:languages:groovy-language.adoc[Groovy] expression
181+
|`@Header`|Inject a xref:components:languages:header-language.adoc[Header] expression
182+
|`@Simple`|Inject an xref:components:languages:simple-language.adoc[Simple] expression
183+
|`@XPath`|Inject an xref:components:languages:xpath-language.adoc[XPath] expression
184+
|===
161185

162186
The table above only list some of the commonly used languages. You can find
163187
a list of all supported xref:components:languages:index.adoc[Languages]
@@ -182,7 +206,7 @@ public class Foo {
182206

183207
==== Advanced example using @Bean
184208

185-
And an example of using the the `@Bean` binding annotation,
209+
And an example of using the `@Bean` binding annotation,
186210
where you can call a xref:components::bean-component.adoc[POJO] to supply
187211
the parameter value:
188212

@@ -210,8 +234,7 @@ public class MyIdGenerator {
210234
public String generate(@Header(name = "user") String user, @Body String payload) throws Exception {
211235
User user = userManager.lookupUser(user);
212236
String userId = user.getPrimaryId();
213-
String id = userId + generateHashCodeForPayload(payload);
214-
return id;
237+
return userId + generateHashCodeForPayload(payload);
215238
}
216239
}
217240
----
@@ -250,7 +273,7 @@ For example in Spring XML:
250273
In this example we have an Exchange that has a User object stored in the
251274
in header. This User object has methods to get some user information. We
252275
want to use xref:components:languages:groovy-language.adoc[Groovy] to inject an expression that
253-
extracts and concats the fullname of the user into the fullName parameter.
276+
extracts and concat the names of the user into the fullName parameter.
254277

255278
[source,java]
256279
----

docs/user-manual/modules/ROOT/pages/pojo-consuming.adoc

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,12 @@ annotation to mark a particular method of a bean as being a consumer
55
method. The value of the annotation defines the Camel
66
xref:endpoint.adoc[Endpoint] to consume from.
77

8-
IMPORTANT: The `@Consume` POJO annotations are not part of any Camel routes, and you cannot use errorHandler or onException with that.
9-
10-
[NOTE]
11-
====
12-
The following steps use the ActiveMQ component which is not yet supported on Camel 4.
13-
====
8+
IMPORTANT: The `@Consume` POJO annotations are not part of any Camel routes, and you cannot use xref:error-handler.adoc[errorHandler] or xref:exception-clause.adoc[onException] with this.
149

1510
For example lets invoke the `onCheese()` method with the String body of the
1611
inbound JMS message from ActiveMQ on the cheese
1712
queue; this will use the xref:type-converter.adoc[Type Converter] to
18-
convert the JMS ObjectMessage or BytesMessage to a String - or just use
19-
a TextMessage from JMS
13+
convert the JMS payload to `String` as declared in the method signature.
2014

2115
[source,java]
2216
----
@@ -31,19 +25,19 @@ public class Foo {
3125

3226
The xref:bean-binding.adoc[Bean Binding] is then used to convert the
3327
inbound xref:components:eips:message.adoc[Message] to the parameter list used to invoke
34-
the method .
28+
the method.
3529

36-
This basically creates a route that looks kinda like this:
30+
This basically creates a route that looks kinda like this (based on the example above):
3731

3832
[source,java]
3933
----
40-
from(uri).bean(theBean, "methodName");
34+
from("activemq:cheese").bean(Foo.class, "onCheese");
4135
----
4236

4337
== Using a property to define the endpoint
4438

45-
The following annotations `@Consume`, `@Produce`, `@EndpointInject`, now
46-
offers a `property` attribute you can use to define the endpoint as a
39+
The following annotations `@Consume`, `@Produce`, `@EndpointInject`, provides
40+
a `property` attribute you can use to define the endpoint uri as a
4741
property on the bean. Then Camel will use the getter method to access
4842
the property.
4943

@@ -52,22 +46,25 @@ For example:
5246
[source,java]
5347
----
5448
public class MyService {
49+
5550
private String serviceEndpoint;
5651
5752
public void setServiceEndpoint(String uri) {
5853
this.serviceEndpoint = uri;
5954
}
6055
61-
public String getServiceEndpoint() {
56+
public String getServiceEndpoint() { // <2>
6257
return serviceEndpoint;
6358
}
6459
65-
@Consume(property = "serviceEndpoint")
60+
@Consume(property = "serviceEndpoint") // <1>
6661
public void onService(String input) {
6762
// do something
6863
}
6964
}
7065
----
66+
<1> the getter for the property
67+
<2> refers to the name of the property
7168

7269
The bean `MyService` has a property named `serviceEndpoint` which has
7370
getter/setter for the property. Now we want to use the bean for
@@ -76,15 +73,33 @@ in the `onService` method. Notice how we use the
7673
`property = "serviceEndpoint` to configure the property that has the
7774
endpoint url.
7875

79-
If you define the bean in Spring XML, then you can configure the property as follows:
8076

77+
[tabs]
78+
====
79+
80+
Spring XML::
81+
+
82+
If you define the bean in Spring XML, then you can configure the property as follows:
83+
+
8184
[source,xml]
8285
----
8386
<bean id="myService" class="com.foo.MyService">
8487
<property name="serviceEndpoint" value="activemq:queue:foo"/>
8588
</bean>
8689
----
8790
91+
YAML::
92+
+
93+
[source,yaml]
94+
----
95+
- beans:
96+
- name: foo
97+
type: com.foo.MyService
98+
properties:
99+
serviceEndpoint: activemq:queue:foo
100+
----
101+
====
102+
88103
This allows you to configure the bean without with any dependency injection style.
89104

90105
=== Advanced use with property naming convention
@@ -95,8 +110,8 @@ The method must be a `getXXX` method.
95110

96111
. Use the property name if explicit given
97112
. If no property name was configured, then use the method name
98-
. Try to get the property with name**Endpoint** (eg with Endpoint as postfix)
99-
. Try to get the property with the name as is (eg no postfix or postfix)
113+
. Try to get the property with name**Endpoint** (e.g. with Endpoint as postfix)
114+
. Try to get the property with the name as is (e.g. no postfix or postfix)
100115
. If the property name starts with **on** then omit that, and try step 3 and 4 again.
101116

102117
So in the example above, we could have defined the `@Consume` annotation as:
@@ -110,7 +125,7 @@ So in the example above, we could have defined the `@Consume` annotation as:
110125
Now the property is named "service" which then would match step 3 from
111126
the algorithm, and have Camel invoke the `getServiceEndpoint` method.
112127

113-
We could also have omitted the property attribute, to make it implicit
128+
We could also have omitted the property attribute, to make it implicit:
114129

115130
[source,java]
116131
----
@@ -122,3 +137,6 @@ Now Camel matches step 5, and loses the prefix *on* in the name, and
122137
looks for 'service' as the property. And because there is a
123138
`getServiceEndpoint` method, Camel will use this method.
124139

140+
== See Also
141+
142+
- xref:pojo-producing.adoc[]

0 commit comments

Comments
 (0)