-1

我写了一个简单的路由,它将获取任何 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!!
4

1 回答 1

1

内联处理器应该这样写......

from("file://output").process(new Processor() {
    public void process(Exchange exchange) throws Exception {
        System.out.println("Recieved exchange:" + e.getIn());
   }
});
于 2012-08-14T22:59:05.150 回答