...
Tip | ||
---|---|---|
If you try to match a
To match the foo queue and disregard any options. |
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
from("direct:start")
.to("mock:foo")
.to("mock:bar").id("bar")
.to("mock:result");
|
...
Selector | Description |
---|---|
| Will only select the first matched node. |
| Will only select the last matched node. |
| Will only select the n'th matched node. The index is zero-based. |
| Will only select the matches node within the given range by index (both inclusive). The index is zero-based. |
maxDeep(to) | Camel 2.14.2/2.15: To limit the selection to at most N level deep in the Camel route tree. The first level is starting from number 1. So number 2 is the children of the 1st level nodes. |
For example to remove the first .to
node in route you can do as follows:
Code Block |
---|
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// only remove the first to node in the route
weaveByType(ToDefinition.class).selectFirst().remove();
}
});
|
...
For example if you want to send a message to a mock:input
endpoint you can do as follows:
Code Block |
---|
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// send the incoming message to mock:input
weaveAddFirst().to("mock:input");
}
});
|
Likewise if you want to easily send a message to a mock:output
endpoint you can do as follows:
Code Block |
---|
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
// send the outgoing message to mock:output
weaveAddLast().to("mock:output");
}
});
|
You can of course combine those in the same advice with:
Code Block |
---|
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveAddFirst().to("mock:input");
weaveAddLast().to("mock:output");
}
});
|
...
You may have routes which consumes messages from endpoints which you want to substitute with another endpoint for easier unit testing. For example a JMS endpoint could be replaced with a SEDA or Direct for unit testing a route, as shown below where we replace the input of the route to a "seda:foo" endpoint:
Code Block |
---|
context.getRouteDefinitions().get(0).adviceWith(context, new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
replaceFromWith("seda:foo");
}
});
|
...