Created
March 11, 2015 20:30
-
-
Save scaryghost/38e23915e725c9f5da6e to your computer and use it in GitHub Desktop.
Apache camel demo taking data from a TCP connection and writing it to outbox/stream.txt. Requires camel-core and camel-mina2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.camel.CamelContext; | |
import org.apache.camel.Exchange; | |
import org.apache.camel.Processor; | |
import org.apache.camel.builder.RouteBuilder; | |
import org.apache.camel.impl.DefaultCamelContext; | |
public class CamelDemo { | |
public static void main(String[] args) throws Exception { | |
CamelContext cContext= new DefaultCamelContext(); | |
RouteBuilder builder= new RouteBuilder() { | |
public void configure() { | |
from("mina2:tcp://localhost:8080?textline=true&sync=false") | |
.setHeader(Exchange.FILE_NAME, constant("stream.txt")) | |
.process(new Processor() { | |
@Override | |
public void process(Exchange exchange) throws Exception { | |
String payload= exchange.getIn().getBody(String.class); | |
exchange.getIn().setBody(String.format("%s%n", payload)); | |
} | |
}) | |
.to("file:outbox?fileExist=Append"); | |
} | |
}; | |
cContext.addRoutes(builder); | |
cContext.start(); | |
try { | |
Thread.sleep(60000); | |
} catch(InterruptedException ex) { | |
} | |
cContext.stop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment