From 434b1d90f691a8fb41c8f48047c881e7a73e94d6 Mon Sep 17 00:00:00 2001 From: Mark Fisher Date: Tue, 22 Jan 2008 03:57:18 +0000 Subject: [PATCH] Added annotation-driven configuration coverage to reference documentation --- .../reference/src/configuration.xml | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/spring-integration-reference/reference/src/configuration.xml b/spring-integration-reference/reference/src/configuration.xml index 6018628265..98d3032437 100644 --- a/spring-integration-reference/reference/src/configuration.xml +++ b/spring-integration-reference/reference/src/configuration.xml @@ -199,6 +199,88 @@
Annotations + In addition to the XML namespace support for configuring Message Endpoints, it is also possible to use + annotations. The class-level @MessageEndpoint annotation indicates that the + annotated class is capable of being registered as an endpoint, and the method-level + @Handler annotation indicates that the annotated method is capable of handling + a message. + @MessageEndpoint(input="fooChannel") +public class FooService { + + @Handler + public void processMessage(Message message) { + ... + } +} + + + In most cases, the annotated handler method should not require the Message type as its + parameter. Instead, the method parameter type can match the message's payload type. + @MessageEndpoint(input="fooChannel") +public class FooService { + + @Handler + public void processFoo(Foo foo) { + ... + } +} + + + As described in the previous section, when the handler method returns a non-null value, the endpoint will + attempt to send a reply. This is consistent across both configuration options (namespace and annotations) in that + the message header's 'replyChannelName' property will be used if available, and the endpoint's default output is + the fallback. To configure the default output for an annotation-driven endpoint, provide the 'defaultOutput' + attribute on the @MessageEndpoint. + @MessageEndpoint(input="exampleChannel", defaultOutput="replyChannel") + + + Finally, just as the 'schedule' sub-element and its 'period' attribute can be provided for a namespace-based + endpoint, the 'pollPeriod' attribute can be provided on the @MessageEndpoint. + @MessageEndpoint(input="exampleChannel", pollPeriod=3000) + + + Two additional annotations are supported, and both act as a special form of handler method: + @Router and @Splitter. As with the + @Handler annotation, methods annotated with either of these two annotations can + either accept the Message itself or the message payload type as the parameter. + When using the @Router annotation, the annotated method can return either the + MessageChannel or String type. In the case of the latter, + the endpoint will resolve the channel name as it does for the default output. Additionally, the method can return + either a single value or a collection. When a collection is returned, the reply message will be sent to multiple + channels. To summarize, the following method signatures are all valid. + @Router +public MessageChannel route(Message message) {...} + +@Router +public List<MessageChannel> route(Message message) {...} + +@Router +public String route(Foo payload) {...} + +@Router +public List<String> route(Foo payload) {...} + + + In addition to payload-based routing, a common requirement is to route based on metadata available within the + message header as either a property or attribute. Rather than requiring use of the + Message type as the method parameter, the @Router + annotation may also map to either a property or attribute name. + @Router(property="customerType") +public String route(String customerType) + +@Router(attribute="orderStatus") +public List<String> route(OrderStatus status) + + + The @Splitter annotation is also applicable to methods that expect either the + Message type or the message payload type, and the return values of the method + should be a collection of any type. If the returned values are not actual Message + objects, then each of them will be sent as the payload of a message. The @Splitter + annotation expects a 'channel' attribute that specifies the channel name to which those messages should be sent. + @Splitter(channel="exampleChannel") +List<LineItem> extractItems(Order order) { + return order.getItems() +}
\ No newline at end of file