Apache Camel User Group Taiwan
2010年12月26日 星期日
Maven in 5 mins.
Maven Hello World.
http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
Maven plug-ins
http://maven.apache.org/guides/getting-started/maven-in-five-minutes.html
Maven plug-ins
2010年12月22日 星期三
How to dynamically update/remove routers?
public class DynamicRoutesTest extends CamelTestSupport {
@Test
public void routesCanBeCreatedDynamically() throws Exception {
MockEndpoint mock = setExpectedMessagesToMock("mock:out-endpoint", 1);
context.addRoutes(createDynamicRoute("dynamicRouteId",
"direct:in", "mock:out-endpoint"));
sendBody("direct:in", "payload to dynamic endpoint");
assertSatisfied(mock);
}
@Test
public void routesCanBeUpdatedDynamicallyToo() throws Exception {
// we're going to change the destination endpoint so the old
one should receive no exchanges and the new on one.
MockEndpoint oldDestination =
setExpectedMessagesToMock("mock:out-endpoint", 0);
MockEndpoint newDestination =
setExpectedMessagesToMock("mock:new-out-endpoint", 1);
context.addRoutes(createDynamicRoute("dynamicRouteId",
"direct:in", "mock:out-endpoint"));
//stop the route by its id
context.stopRoute("dynamicRouteId");
context.addRoutes(redirectTrafficToDifferentEndpoint("dynamicRouteId",
"mock:new-out-endpoint"));
sendBody("direct:in", "payload to dynamic endpoint");
assertSatisfied(oldDestination, newDestination);
}
public RouteBuilder createDynamicRoute(final String id, final
String uri, final String touri) {
return new RouteBuilder() {
public void configure() throws Exception {
from(uri).id(id).to(touri);
}
};
}
public RouteBuilder redirectTrafficToDifferentEndpoint(final
String id, final String newDestination) {
return new RouteBuilder() {
public void configure() throws Exception {
RouteDefinition old = getContext().getRouteDefinition(id);
for (FromDefinition from : old.getInputs()) {
from(from.getUri()).id(old.getId()).to(newDestination);
}
}
};
}
private MockEndpoint setExpectedMessagesToMock(String mockUri, int
expectedMessages) {
MockEndpoint mock = getMockEndpoint(mockUri);
mock.expectedMessageCount(expectedMessages);
return mock;
}
private void assertSatisfied(MockEndpoint... mocks) throws
InterruptedException {
for (MockEndpoint mock : mocks) {
mock.await(1, TimeUnit.SECONDS);
mock.assertIsSatisfied();
}
}
}
Quoted above code segments from
http://camel.465427.n5.nabble.com/How-to-update-remove-camel-route-td478637.html
@Test
public void routesCanBeCreatedDynamically() throws Exception {
MockEndpoint mock = setExpectedMessagesToMock("mock:out-endpoint", 1);
context.addRoutes(createDynamicRoute("dynamicRouteId",
"direct:in", "mock:out-endpoint"));
sendBody("direct:in", "payload to dynamic endpoint");
assertSatisfied(mock);
}
@Test
public void routesCanBeUpdatedDynamicallyToo() throws Exception {
// we're going to change the destination endpoint so the old
one should receive no exchanges and the new on one.
MockEndpoint oldDestination =
setExpectedMessagesToMock("mock:out-endpoint", 0);
MockEndpoint newDestination =
setExpectedMessagesToMock("mock:new-out-endpoint", 1);
context.addRoutes(createDynamicRoute("dynamicRouteId",
"direct:in", "mock:out-endpoint"));
//stop the route by its id
context.stopRoute("dynamicRouteId");
context.addRoutes(redirectTrafficToDifferentEndpoint("dynamicRouteId",
"mock:new-out-endpoint"));
sendBody("direct:in", "payload to dynamic endpoint");
assertSatisfied(oldDestination, newDestination);
}
public RouteBuilder createDynamicRoute(final String id, final
String uri, final String touri) {
return new RouteBuilder() {
public void configure() throws Exception {
from(uri).id(id).to(touri);
}
};
}
public RouteBuilder redirectTrafficToDifferentEndpoint(final
String id, final String newDestination) {
return new RouteBuilder() {
public void configure() throws Exception {
RouteDefinition old = getContext().getRouteDefinition(id);
for (FromDefinition from : old.getInputs()) {
from(from.getUri()).id(old.getId()).to(newDestination);
}
}
};
}
private MockEndpoint setExpectedMessagesToMock(String mockUri, int
expectedMessages) {
MockEndpoint mock = getMockEndpoint(mockUri);
mock.expectedMessageCount(expectedMessages);
return mock;
}
private void assertSatisfied(MockEndpoint... mocks) throws
InterruptedException {
for (MockEndpoint mock : mocks) {
mock.await(1, TimeUnit.SECONDS);
mock.assertIsSatisfied();
}
}
}
Quoted above code segments from
http://camel.465427.n5.nabble.com/How-to-update-remove-camel-route-td478637.html
2010年12月19日 星期日
using JMS or ActiveMQ instead
The SEDA component does not implement any kind of persistence or recovery, if the VM terminates while messages are yet to be processed. If you need persistence, reliability or distributed SEDA, try using either JMS or ActiveMQ.
The other asynchronous endpoint (VM)
The vm: component provides asynchronous SEDA behavior so that messages are exchanged on a BlockingQueue and consumers are invoked in a separate thread pool to the producer.
Synchronous endpoints (direct:)
Direct uses no threading; it directly invokes the consumer when sending.
訂閱:
意見 (Atom)