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.
Events are totally different from others.
Event adds a listener to Spring's application events; so the consumer is invoked the same thread as Spring notifies events. Event differs in that the payload should be a Spring ApplicationEvent object whereas Direct, SEDA and VM can use any payload
What's difference between VM and SEDA?
VM and SEDA endpoints are basically the same; they both offer asychronous in memory SEDA queues; they differ in visibility endpoints are visible inside the same JVM or within the same CamelContext respectively.
First kind of asynchronous endpoint (SEDA)
from(“seda:start”).beanRef(“someBean”, “someMethod”);
Exchanges (messages) put to the seda:start endpoint will be processed through the remainder of the Camel route. The SEDA endpoint encapsulates an in-memory queue used as an entry point to the route. All messages are processed asynchronously. In the example above, the messages would be routed to the someMethod method on a spring bean named someBean.
Exchanges (messages) put to the seda:start endpoint will be processed through the remainder of the Camel route. The SEDA endpoint encapsulates an in-memory queue used as an entry point to the route. All messages are processed asynchronously. In the example above, the messages would be routed to the someMethod method on a spring bean named someBean.
Camel Terminologies
A component is to be a factory and manager of Endpoints.
The Injector is a pluggable strategy to any IoC container such as Spring or Guice to be able to create and dependency-inject objects of a certain type.
HawtDB is a very lightweight and embedable key value database. It allows together with Camel to provide persistent support for various Camel features such as Aggregator.
Apache Camel’s SEDA (Staged Event-Driven Architecture) endpoints (http://camel.apache.org/seda.html) provide a useful and quick mechanism to implement asynchronous, event-driven processing within your applications. See http://www.eecs.harvard.edu/~mdw/proj/seda/ for the original description of the SEDA architecture.
The Injector is a pluggable strategy to any IoC container such as Spring or Guice to be able to create and dependency-inject objects of a certain type.
HawtDB is a very lightweight and embedable key value database. It allows together with Camel to provide persistent support for various Camel features such as Aggregator.
Apache Camel’s SEDA (Staged Event-Driven Architecture) endpoints (http://camel.apache.org/seda.html) provide a useful and quick mechanism to implement asynchronous, event-driven processing within your applications. See http://www.eecs.harvard.edu/~mdw/proj/seda/ for the original description of the SEDA architecture.
Input
-- ask user to enter a number --
<<
from uri="stream:in?promptMessage=Enter a number to be added (use STOP to end, and ctrl+c to shutdown Camel): &promptDelay=1000"
//>>
<<
from uri="stream:in?promptMessage=Enter a number to be added (use STOP to end, and ctrl+c to shutdown Camel): &promptDelay=1000"
//>>
2010年12月17日 星期五
send message to my gtalk
quoted from
http://www.andrejkoelewijn.com/wp/2009/02/28/groovy-and-grape-easiest-way-to-send-gtalk-message-with-apache-camel/
INSTALL GROOVY AND add $HOME/.groovy/grapeConfig.xml file first. (get grapeConfig.xml from above URL)
#!/usr/local/groovy-1.6.0/bin/groovy
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.language.groovy.GroovyRouteBuilder;
@Grab(group='org.apache.camel', module='camel-groovy', version='1.6.0')
@Grab(group='org.apache.camel', module='camel-xmpp', version='1.6.0')
@Grab(group='org.apache.camel', module='camel-core', version='1.6.0')
class SampleRoute extends GroovyRouteBuilder {
protected void configure(){
from("file:///tmp/jabber").
to("xmpp://talk.google.com:5222/mingderwang@gmail.com?serviceName=gmail.com&user=yourname&password=secrect");
}
}
def camelCtx = new DefaultCamelContext()
camelCtx.addRoutes(new SampleRoute());
camelCtx.start();
http://www.andrejkoelewijn.com/wp/2009/02/28/groovy-and-grape-easiest-way-to-send-gtalk-message-with-apache-camel/
INSTALL GROOVY AND add $HOME/.groovy/grapeConfig.xml file first. (get grapeConfig.xml from above URL)
#!/usr/local/groovy-1.6.0/bin/groovy
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.language.groovy.GroovyRouteBuilder;
@Grab(group='org.apache.camel', module='camel-groovy', version='1.6.0')
@Grab(group='org.apache.camel', module='camel-xmpp', version='1.6.0')
@Grab(group='org.apache.camel', module='camel-core', version='1.6.0')
class SampleRoute extends GroovyRouteBuilder {
protected void configure(){
from("file:///tmp/jabber").
to("xmpp://talk.google.com:5222/mingderwang@gmail.com?serviceName=gmail.com&user=yourname&password=secrect");
}
}
def camelCtx = new DefaultCamelContext()
camelCtx.addRoutes(new SampleRoute());
camelCtx.start();
訂閱:
意見 (Atom)