StreamPage edited by Claus IbsenStream ComponentThe stream: component provides access to the System.in, System.out and System.err streams as well as allowing streaming of file and URL. URI formatstream:in[?options] stream:out[?options] stream:err[?options] stream:header[?options]
Message contentThe stream: component supports either String or byte[] for writing to streams. Just add either String or byte[] content to the message.in.body. SamplesIn the following sample we route messages from the direct:in endpoint to the System.out stream: @Test public void testStringContent() throws Exception { template.sendBody("direct:in", "Hello Text World\n"); } @Test public void testBinaryContent() { template.sendBody("direct:in", "Hello Bytes World\n".getBytes()); } protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { from("direct:in").to("stream:out"); } }; } The following sample demonstrates how the header type can be used to determine which stream to use. In the sample we use our own output stream, MyOutputStream. private OutputStream mystream = new MyOutputStream(); private StringBuffer sb = new StringBuffer(); @Test public void testStringContent() { template.sendBody("direct:in", "Hello"); // StreamProducer appends \n in text mode assertEquals("Hello\n", sb.toString()); } @Test public void testBinaryContent() { template.sendBody("direct:in", "Hello".getBytes()); // StreamProducer is in binary mode so no \n is appended assertEquals("Hello", sb.toString()); } protected RouteBuilder createRouteBuilder() { return new RouteBuilder() { public void configure() { from("direct:in").setHeader("stream", constant(mystream)). to("stream:header"); } }; } private class MyOutputStream extends OutputStream { public void write(int b) throws IOException { sb.append((char)b); } } The following sample demonstrates how to continuously read a file stream (analogous to the UNIX tail command): from("stream:file?fileName=/server/logs/server.log?scanStream=true&scanStreamDelay=1000").to("bean:logService?method=parseLogLine"); See Also
Change Notification Preferences
View Online
|
View Change
|
Add Comment
|
- [CONF] Apache Camel > Stream confluence
- [CONF] Apache Camel > Stream confluence
- [CONF] Apache Camel > Stream confluence
- [CONF] Apache Camel > Stream confluence
- [CONF] Apache Camel > Stream confluence