diff --git a/src/docbkx/gateway.xml b/src/docbkx/gateway.xml index ece10d5dea..39448c9468 100644 --- a/src/docbkx/gateway.xml +++ b/src/docbkx/gateway.xml @@ -4,29 +4,6 @@ Inbound Messaging Gateways -
- SimpleMessagingGateway - - Even though the MessageChannelTemplate is fairly straightforward, it does not hide the - details of messaging from your application code. To support working with plain Objects instead of messages, - Spring Integration provides SimpleMessagingGateway with the following methods: - sendAndReceiveMessage(Object object);]]> - It enables configuration of a request and/or reply channel and delegates to instances of the - InboundMessageMapper and OutboundMessageMapper - strategy interfaces. - SimpleMessagingGateway gateway = new SimpleMessagingGateway(inboundMapper, outboundMapper); - gateway.setRequestChannel(requestChannel); - gateway.setReplyChannel(replyChannel); - Object result = gateway.sendAndReceive("test"); - -
-
GatewayProxyFactoryBean @@ -128,5 +105,42 @@
+
+ Asynchronous Gateway + + As a pattern Messaging Gateway is a very nice way to hide you from messaging-specific code while still exposing full capabilities of the + messaging system. And GatewayProxyFactoryBean provides a convenient way to expose Proxy over the service-interface thus giving you a POJO-based access + to a messaging system.  But when gateway is exposed via simple POJO method which returns value it does imply that for each Request message (method is invoked) + there must be a Reply message (method has returned). Since Messaging systems naturally are asynchronous you may not always able to + guarantee the contract where "for each request there will always be be a reply".  + With Spring Integration 2.0 we are introducing an Asynchronous Gateway which is a convenient way to initiate flows where you may not know + if reply is coming or how long will it take for it to come. + + + A natural way to handle these types of scenarios in Java would be java.util.concurrent.Futures and that is exactly what Spring Integration uses to create an Asynchronous Gateway. + + + From the XML configuration, there is nothing different and you still define Asynchronous Gateway the same way as regular Gateway + ]]> + However the Gateway Interface (service-interface) is a bit different. + + public interface MathServiceGateway { + Future<Integer> multiplyByTwo(int i); +} + + + As you can see from the example above the return type for the gateway method is Future. When GatewayProxyFactoryBean sees that the + return type of the gateway method is Future it immediately switches to the async mode by utilizing AsyncTaskExecutor + That is all. The call to a method always returns immediately with Future encapsulating  the interaction with the framework. + Now you can interact with the Future at your own pace to get the result, timeout, get the exception etc... + MathServiceGateway mathService = ac.getBean("mathService", MathServiceGateway.class); +Future<Integer> result = mathService.multiplyByTwo(number); +int finalResult =  result.get(1000, TimeUnit.SECONDS); +For more detailed example please refer to async-gateway sample distributed with Spring Integration samples. + + +
\ No newline at end of file