Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
Object response = template.requestBody("<hello/>");

// you can cast the response directly
String ret = template.requestBody("<hello/>", String.class);

// or specify the endpoint directly
String ret = template.requestBody("cxf:bean:HelloWorldService", "<hello/>", String.class);

 

Fluent interface (camel 2.18.0)

The FluentProducerTemplate provides a fluent syntax to ProducerTemplate,, examples:

 

Code Block
languagejava
titleSet headers and body
Integer result = FluentProducerTemplate.on(context)
    .withHeader("key-1", "value-1")
    .withHeader("key-2", "value-2")
    .withBody("Hello")
    .to("direct:inout")
    .request(Integer.class)
Code Block
languagejava
titleUse a processor
Integer result = FluentProducerTemplate.on(context)
    .withProcessor(exchange -> exchange.getIn().setBody("Hello World"))
    .to("direct:exception")
    .request(Integer.class);
Code Block
languagejava
titleCustomize template
Object result = FluentProducerTemplate.on(context)
    .withTemplateCustomizer(
        template -> {
            template.setExecutorService(myExecutor);
            template.setMaximumCacheSize(10);
        }
    )
    .withBody("the body")
    .to("direct:start")
    .request()