spring-projects/spring-amqp — pull request #201 by snicoll (2014-08-06 14:31:09+00:00)
Title: Rabbit annotation-driven endpoints

This commit adds the support of Rabbit annotated endpoint. Can be activated by both by `@EnableRabbit` or `` and detects methods of managed beans annotated with `@RabbitListener`, either directly or through a meta-annotation.

Containers are created and managed under the cover by a registry at application startup time. Container creation is delegated to a `RabbitListenerContainerFactory` that is identified by the `containerFactory` attribute of the `RabbitListener` annotation. Containers can be retrieved from the registry using a custom id that can be specified directly on the annotation.

The configuration can be fine-tuned by implementing the `RabbitListenerConfigurer` interface which gives access to the registrar used to register endpoints. This includes a programmatic registration of endpoints in complement to the declarative approach. A default `RabbitListenerContainerFactory` can also be specified to be used if no `containerFactory` has been set on the annotation.

Annotated methods can have flexible method arguments that are similar to what `@MessageMapping` provides. In particular, rabbit listener endpoint methods can fully use the messaging abstraction, including convenient header accessor. It is also possible to inject the raw `org.springframework.amqp.core.Message` and the `Channel` for more
advanced use cases. The payload can be injected as long as the conversion service is able to convert it from the original body. By default, a `DefaultMessageHandlerMethodFactory` is used but it can be configured further to support additional method arguments or to customize conversion and validation support.

The return type of an annotated method can also be an instance of Spring's Message abstraction. Instead of just converting the payload, such response type allows to communicate standard and custom headers.

`AmqpHeaders` and `DefaultAmqpHeaderMapper` have been copied from Spring integration. `SimpleAmqpHeaderMapper` is a reduced version of the Spring integration counter part that does not support deprecated fields and JSON specific constructs. Method hook points are available so that a future version of Spring Integration can integrate those customizations in an extension. Note that the default know maps all user-defined headers so that the generated Message abstraction has all the information stored in the protocol specific message.

`MessagingMessageConverter` is a new `MessageConverter` implementation that produces a `org.springframework.messaging.Message` out of an AMQP message and vice versa. `AmqpMessageHeaderAccessor` provides an easy access of AMQP specific headers from a standard Message.

**NOTE**: you need [a special SNAPSHOT of the Spring Framework](https://github.com/snicoll/spring-framework/tree/amqp-mapper) to be able to build this branch. This branch is about to be merged in time for Spring 4.1.RC2