Test project for remote exception handling using Spring Integration AMQP. This implementation uses direct reply-to mechanism in order to decouple client and server.
Build with mvn clean install
and run MainServer
(you can stop it with Enter key), then MainClient
. The client will send a "valid" request first, then an invalid one that will raise an exception on the server. The exception will be wrapped in a response message and will be rethrown on the client side, just like a RPC.
error-channel
: this channel catches errors and forward them to theErrorHandler
.ErrorHandler
: this service inspects theMessage
and wraps exception in aRuntimeExceptionHolder
object (this is necessary due to the wayMessagingGatewaySupport.doSendAndReceive
works: if the response body is aThrowable
, it is rethrown) and returns it as response with the original response headers (here we copy the original direct reply-to headers in the error message).
ClientErrorInterceptor
: this interceptor checks the response body type: if it's aRuntimeExceptionHolder
, the original exception is unwrapped and thrown to the caller.
We are waiting for spring-rabbit 2.0.0 that will support direct reply-to with AsyncMessagingTemplate in order to achieve the same feature, but with non-blocking mode (see AMQP-616).