The synchronous send methods are a collection of methods that you can use to invoke a producer endpoint, where the current thread blocks until the method invocation is complete and the reply (if any) has been received. These methods are compatible with any kind of message exchange protocol.
The basic send()
method is a general-purpose method that sends
the contents of an Exchange
object to an endpoint, using the
message exchange pattern (MEP) of the exchange. The return value is the exchange
that you get after it has been processed by the producer endpoint (possibly
containing an Out message, depending on the MEP).
There are three varieties of send()
method for sending an
exchange that let you specify the target endpoint in one of the following ways:
as the default endpoint, as an endpoint URI, or as an Endpoint
object.
Exchange send(Exchange exchange); Exchange send(String endpointUri, Exchange exchange); Exchange send(Endpoint endpoint, Exchange exchange);
A simple variation of the general send()
method is to use a
processor to populate a default exchange, instead of supplying the exchange
object explicitly (see Synchronous invocation with a processor for
details).
The send()
methods for sending an exchange populated by a
processor let you specify the target endpoint in one of the following ways: as
the default endpoint, as an endpoint URI, or as an Endpoint
object.
In addition, you can optionally specify the exchange's MEP by supplying the
pattern
argument, instead of accepting the default.
Exchange send(Processor processor); Exchange send(String endpointUri, Processor processor); Exchange send(Endpoint endpoint, Processor processor); Exchange send( String endpointUri, ExchangePattern pattern, Processor processor ); Exchange send( Endpoint endpoint, ExchangePattern pattern, Processor processor );
If you are only concerned with the contents of the message body that you want
to send, you can use the sendBody()
methods to provide the message
body as an argument and let the producer template take care of inserting the
body into a default exchange object.
The sendBody()
methods let you specify the target endpoint in one
of the following ways: as the default endpoint, as an endpoint URI, or as an
Endpoint
object. In addition, you can optionally specify the
exchange's MEP by supplying the pattern
argument, instead of
accepting the default. The methods without a
pattern
argument return void
(even though the
invocation might give rise to a reply in some cases); and the methods
with a pattern
argument return either the
body of the Out message (if there is one) or the body of
the In message (otherwise).
void sendBody(Object body); void sendBody(String endpointUri, Object body); void sendBody(Endpoint endpoint, Object body); Object sendBody( String endpointUri, ExchangePattern pattern, Object body ); Object sendBody( Endpoint endpoint, ExchangePattern pattern, Object body );
For testing purposes, it is often interesting to try out the effect of a
single header setting and the
sendBodyAndHeader()
methods are useful for this kind of header
testing. You supply the message body and header setting as arguments to
sendBodyAndHeader()
and let the producer template take care of
inserting the body and header setting into a default exchange object.
The sendBodyAndHeader()
methods let you specify the target
endpoint in one of the following ways: as the default endpoint, as an endpoint
URI, or as an Endpoint
object. In addition, you can optionally
specify the exchange's MEP by supplying the pattern
argument,
instead of accepting the default. The methods without a
pattern
argument return void
(even though the
invocation might give rise to a reply in some cases); and the methods
with a pattern
argument return either the
body of the Out message (if there is one) or the body of
the In message (otherwise).
void sendBodyAndHeader( Object body, String header, Object headerValue ); void sendBodyAndHeader( String endpointUri, Object body, String header, Object headerValue ); void sendBodyAndHeader( Endpoint endpoint, Object body, String header, Object headerValue ); Object sendBodyAndHeader( String endpointUri, ExchangePattern pattern, Object body, String header, Object headerValue ); Object sendBodyAndHeader( Endpoint endpoint, ExchangePattern pattern, Object body, String header, Object headerValue );
The sendBodyAndHeaders()
methods are similar to the
sendBodyAndHeader()
methods, except that instead of supplying
just a single header setting, these methods allow you to specify a complete hash
map of header settings.
void sendBodyAndHeaders( Object body, Map<String, Object> headers ); void sendBodyAndHeaders( String endpointUri, Object body, Map<String, Object> headers ); void sendBodyAndHeaders( Endpoint endpoint, Object body, Map<String, Object> headers ); Object sendBodyAndHeaders( String endpointUri, ExchangePattern pattern, Object body, Map<String, Object> headers ); Object sendBodyAndHeaders( Endpoint endpoint, ExchangePattern pattern, Object body, Map<String, Object> headers );
You can try out the effect of setting a single exchange property using the
sendBodyAndProperty()
methods. You supply the message body and
property setting as arguments to sendBodyAndProperty()
and let the
producer template take care of inserting the body and exchange property into a
default exchange object.
The sendBodyAndProperty()
methods let you specify the target
endpoint in one of the following ways: as the default endpoint, as an endpoint
URI, or as an Endpoint
object. In addition, you can optionally
specify the exchange's MEP by supplying the pattern
argument,
instead of accepting the default. The methods without a
pattern
argument return void
(even though the
invocation might give rise to a reply in some cases); and the methods
with a pattern
argument return either the
body of the Out message (if there is one) or the body of
the In message (otherwise).
void sendBodyAndProperty( Object body, String property, Object propertyValue ); void sendBodyAndProperty( String endpointUri, Object body, String property, Object propertyValue ); void sendBodyAndProperty( Endpoint endpoint, Object body, String property, Object propertyValue ); Object sendBodyAndProperty( String endpoint, ExchangePattern pattern, Object body, String property, Object propertyValue ); Object sendBodyAndProperty( Endpoint endpoint, ExchangePattern pattern, Object body, String property, Object propertyValue );