Sachin Singh
Sachin Singh

Reputation: 3

How to send data to a netty4 socket in a apache camel route

I have a route

'Server received: ' + exchange.getIn().getBody(String.class)

I want to send data to this socket using some java client . How can i do that?

Upvotes: 0

Views: 309

Answers (1)

Thomas
Thomas

Reputation: 1140

'Server received: ' + exchange.getIn().getBody(String.class) is not a camel route, it is more a processor that print the body content. You need to define a CamelContext, add a route with a custom processor

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 Camel doc

Upvotes: 1

Related Questions