Sep 22nd, 2011, 04:56 PM
RabbitTemplate/RabbitGatewaySupport incompatible with JDK proxy
We want to advise RabbitTemplate methods (such as send) as part of tracing support in our application. We are declaring a RabbitTemplate bean in our XML schema with a custom message converter and then injecting it into a bean of a class which extends RabbitGatewaySupport.
Spring AOP autoproxy will generate a JDK proxy by default for our advice since RabbitTemplate implements the RabbitOperations interface. However, RabbitGatewaySupport expects a RabbitTemplate and thus the injection of the proxy fails. We can work around this by forcing the use of CGLIB proxies, but this changes all the proxies in our application, including transactional proxies introduced by tx:annotation-driven, and is clearly undesirable. Since RabbitGatewaySupport is relatively small we will probably either use a modified local version or just skip using it entirely.
If RabbitGatewaySupport took an instance of RabbitOperations then I think a JDK proxy could be used. I think getConnectionFactory() would need to be added to the RabbitOperations interface and don't know if there are other places in Spring AMQP where RabbitTemplate can be injected that would be affected.
Sep 23rd, 2011, 08:25 AM
I agree that is pretty bad. RabbitGatewaySupport is pretty thin though, so I expect the best workaround is to simply copy that and modify it. If you raise a ticket in JIRA we can look at fixing it properly.
Sep 23rd, 2011, 01:12 PM
Thanks, I'll open a ticket. We are good with the work-around of copy/modifying or simply not using. Would be nice to have it fixed though in case features are added to RabbitGatewaySupport in the future that make the workaround less palatable.