0

我有路线

'服务器收到:' + exchange.getIn().getBody(String.class)

我想使用一些 java 客户端向这个套接字发送数据。我怎样才能做到这一点?

4

1 回答 1

1

'Server received:' + exchange.getIn().getBody(String.class) 不是骆驼路线,它更像是一个打印正文内容的处理器。您需要定义一个 CamelContext,添加一个带有自定义处理器的路由

CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder() {
    public void configure() {

        from("direct:start")
        .process(new Processor() {
                      public void process(Exchange exchange) throws Exception {
                         String body = exchange.getIn().getBody(String.class);
                         System.out.println("Server received: " + body);
                    }
                  })
    }
});

ProducerTemplate template = context.createProducerTemplate();
context.start();
template.sendBody("direct:start", "Hello World");

RouteBuilder 骆驼文档

于 2018-12-12T12:33:20.050 回答