Created
August 14, 2014 20:44
-
-
Save steppat/20bb1763b6baac09ccc9 to your computer and use it in GitHub Desktop.
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
package br.com.caelum.camel; | |
import org.apache.camel.CamelContext; | |
import org.apache.camel.Exchange; | |
import org.apache.camel.LoggingLevel; | |
import org.apache.camel.builder.RouteBuilder; | |
import org.apache.camel.impl.DefaultCamelContext; | |
import org.apache.camel.model.dataformat.XmlJsonDataFormat; | |
public class TesteRoteamento { | |
public static void main(String[] args) throws Exception { | |
CamelContext context = new DefaultCamelContext(); | |
context.addRoutes(new RouteBuilder() { | |
@Override | |
public void configure() throws Exception { | |
errorHandler( | |
deadLetterChannel("file:erro") | |
.maximumRedeliveries(2) | |
.redeliveryDelay(2000).logStackTrace(true) | |
); | |
// onException(RuntimeException.class) | |
// .log("Exceção Processando ${file:name}") | |
// .handled(true) | |
// .to("file:2_exception"); | |
from("file:entrada?delay=5s&noop=true") | |
.log(LoggingLevel.INFO, "Processando mensagem ${id}") | |
.bean(ValidadorPedido.class, "validar") | |
.transform(body(String.class).regexReplaceAll("nomeAutor", "autor")) | |
.to("file:saida") | |
.to("direct:itens") | |
.to("direct:pagamento"); | |
from("direct:itens") | |
.split() | |
.xpath("/pedido/itens") | |
.convertBodyTo(String.class) | |
.marshal().xmljson() | |
.log("${body}") | |
.setHeader(Exchange.FILE_NAME,simple("${file:name.noext}.json")) | |
.to("file:itens"); | |
from("direct:pagamento") | |
.split().xpath("/pedido/pagamento").convertBodyTo(String.class) | |
.to("velocity:nota.vm") | |
.to("file:pagamentos"); | |
} | |
}); | |
context.start(); | |
Thread.sleep(30*1000); | |
context.stop(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment