我编写了一个简单的路由,它将获取任何http请求并将其保存在file:output中。 保存后,将创建一个可读取所有请求的处理器。
这是我的代码:
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 LoadBalancer {
public static void main(String args[]) throws Exception {
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
public void configure() {
from("jetty://http://localhost:8080")
.to("file:output");
from("file://output").process(new processor()
{
public void process(Exchange e)
{
System.out.println("Recieved exchange:" + e.getIn());
}
}
);
//.loadBalance().roundRobin().to("http://172.28.39.138:8080","http://172.168.20.118:8080");
}
});
context.start();
Thread.sleep(100000);
context.stop();
}
}
现在当我编译它时,我收到以下错误:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The method process(Processor) in the type ProcessorDefinition<RouteDefinition> is not applicable for the arguments (new processor(){})
processor cannot be resolved to a type
On the line `from("file://output").process(new processor()`
I couldn't figure out what kind of error it it.
Am I doing anything wrong in the code?
Any help would be very much appreciated.
Cheers!!
答案 0 :(得分:1)
内联Processors应该像这样写......
from("file://output").process(new Processor() {
public void process(Exchange exchange) throws Exception {
System.out.println("Recieved exchange:" + e.getIn());
}
});