Versions Compared

Key

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

...

The sendBody() method allows you to send any object to an endpoint easily.

Code Block

ProducerTemplate template = exchange.getContext().createProducerTemplate();

// send to default endpoint
template.sendBody("<hello>world!</hello>");

// send to a specific queue
template.sendBody("activemq:MyQueue", "<hello>world!</hello>");

// send with a body and header 
template.sendBodyAndHeader("activemq:MyQueue", 
   "<hello>world!</hello>",
   "CustomerRating", "Gold");

...

e.g. lets invoke an endpoint and get the response

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);