Using Camel Stream Component



The stream Camel component provides access to the System.in, System.out and System.err streams as well as allowing streaming of file and URL.

When using the stream component, the following URI syntax is available:

  • stream:in[?options]
  • stream:out[?options]
  • stream:err[?options]
  • stream:header[?options]

In the following example, we are using the stream:out to perform a System.out of the content of files contained in the folder C:\Camel\In

package com.sample;

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.spi.DataFormat;

public class Hello {

	public static void main(String args[]) throws Exception {
		CamelContext context = new DefaultCamelContext();
		final DataFormat bindy = new BindyCsvDataFormat("com.sample.model");
		context.addRoutes(new RouteBuilder() {
			public void configure() {
 				 from("file:C:\\camel\\in?noop=true")
				 .to("stream:out"); 
				
			 
			}
		});

		context.start();
		Thread.sleep(10000);
		context.stop();
	}

}

Note that you can combine different type of streams in your route: for example, the following RouteBuilder takes an input stream from the Console and prints it to the System.out stream:

context.addRoutes(new RouteBuilder() {
	public void configure() {
		  from("stream:in")
		 .to("stream:out"); 	 
	}
});
FREE WildFly Application Server - JBoss - Quarkus - Drools Tutorials
Cookie Policy

Cookie Policy This website uses cookies that are necessary to its functioning and required to achieve the purposes illustrated in the privacy policy. By accepting this OR scrolling this page OR continuing to browse, you agree to our privacy policy.

© 2020 Your Company. All Rights Reserved. Designed By JoomShaper

Please publish modules in offcanvas position.