What is the usage/clarify of weaveAddLast in a camel route ?
Issue
- We have a route defined like the following,
from(EXAMPLE_ROUTE)
.routeId(ROUTE_ID)
.filter(header("TYPE").isNotEqualTo(FILTER))
.choice()
.when(header("TYPE").isEqualTo(TYPE1)).to("amq:" + QUEUE1)
.when(header("TYPE").isEqualTo(TYPE2)).to("amq:" + QUEUE2)
.when(header("TYPE").isEqualTo(TYPE3)).to("amq:" + QUEUE3)
.otherwise().log(INFO, "Not interested with TYPE = ${header.TYPE}");
And the following test failed on MOCK_END.expectedMessageCount(0);
@Before
public void routeSetup() throws Exception {
String rrpQ = "mock:Q1";
String rolloverQ = "mock:Q2";
String outrightQ = "mock:Q3";
String end = "mock:end";
// Create AdviceWithRouteBuilder to Advice the Route
AdviceWithRouteBuilder adviceWithRouteBuilder = new AdviceWithRouteBuilder() {
@Override
public void configure() throws Exception {
weaveByToString("To[amq:" + QUEUE1 + "]").replace().to(rrpQ);
weaveByToString("To[amq:" + QUEUE2 + "]").replace().to(outrightQ);
weaveByToString("To[amq:" + QUEUE3 + "]").replace().to(rolloverQ);
weaveAddLast().to(end);
}
};
// Apply Advice to Route under Test
context.getRouteDefinition(ROUTE_ID).adviceWith(context, adviceWithRouteBuilder);
MOCK_Q1 = getMockEndpoint(rrpQ);
MOCK_Q2 = getMockEndpoint(rolloverQ);
MOCK_Q3 = getMockEndpoint(outrightQ);
MOCK_END = getMockEndpoint(end);
}
@Test
public void routingRRPEvent() throws Exception {
// prepare
context.start();
// invoke
template.sendBodyAndHeader(EXAMPLE_ROUTE, constant(null), "TYPE", TYPE1);
// conditions to verify
MOCK_Q2.expectedMessageCount(0);
MOCK_Q3.expectedMessageCount(0);
MOCK_Q1.expectedHeaderReceived("TYPE", TYPE1);
MOCK_Q1.expectedMessageCount(1);
MOCK_END.expectedMessageCount(0); // failed
// verify
assertMockEndpointsSatisfied();
}
- We are expecting the
MOCK_END.expectedMessageCount
to be 0 but what we actually get the result 1. When we exam the message with debug mode, we learned the message fromMOCK_END
is the same asMOCK_Q1
. -
Can you please explains how
weaveAddLast()
works? We add more tests given different when condition and theMOCK_END
is always give me the exactly the same message as the when condition we are getting. -
It looks like the
weaveAddLast()
add an node to the route end during runtime depends on wherever the given message is heading to, instead of just add the a node at the very end of the route definition?
Environment
- Red Hat JBoss Fuse
- 6.2.x
- Apache Camel
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.