The producer template provides a variety of methods for invoking a producer endpoint asynchronously, so that the main thread does not block while waiting for the invocation to complete and the reply message can be retrieved at a later time. The asynchronous send methods described in this section are compatible with any kind of message exchange protocol.
The basic asyncSend()
method takes an Exchange
argument and invokes an endpoint asynchronously, using the message exchange
pattern (MEP) of the specified exchange. The return value is a
java.util.concurrent.Future
object, which is a ticket you can
use to collect the reply message at a later time—for details of how to
obtain the return value from the Future
object, see Asynchronous invocation.
The following asyncSend()
methods let you specify the target
endpoint in one of the following ways: as an endpoint URI, or as an
Endpoint
object.
Future<Exchange> asyncSend(String endpointUri, Exchange exchange); Future<Exchange> asyncSend(Endpoint endpoint, Exchange exchange);
A simple variation of the general asyncSend()
method is to use a
processor to populate a default exchange, instead of supplying the exchange
object explicitly.
The following asyncSend()
methods let you specify the target
endpoint in one of the following ways: as an endpoint URI, or as an
Endpoint
object.
Future<Exchange> asyncSend(String endpointUri, Processor processor); Future<Exchange> asyncSend(Endpoint endpoint, Processor processor);
If you are only concerned with the contents of the message body that you want
to send, you can use the asyncSendBody()
methods to send a message
body asynchronously and let the producer template take care of inserting the
body into a default exchange object.
The asyncSendBody()
methods let you specify the target endpoint
in one of the following ways: as an endpoint URI, or as an Endpoint
object.
Future<Object> asyncSendBody(String endpointUri, Object body); Future<Object> asyncSendBody(Endpoint endpoint, Object body);