Uploaded image for project: 'Spring AMQP'
  1. Spring AMQP
  2. AMQP-831

RabbitListener annotation on bean method should place the listener on the returned bean instead of on the method

    XMLWordPrintable

Details

    Description

      I have tried putting the @RabbitListener annotation on a bean method. My intend was to use the returned bean as the listener. Instead the listener got placed on the method.

      @Configuration
       public class RemoveReceiverConfiguration {
           @Bean
           @RabbitListener(queues = "listenerqueue")
           public FieldValueReceiver blssRemoveReceiver(Listener listener) {
               return new FieldValueReceiver(listener);
           }
      
         private static class FieldValueReceiver {
             private Listener listener;
      
            FieldValueReceiver(Listener listener) {
               this.listener = listener;
                   }
      
            @RabbitHandler
             public void handle(String message) {
               listener.handle(message);
      
                 }
      
           }
       }
       

      Expectation: Whenever a message arrives on queue 'listenerqueue' the method 'handle' on FieldValueReceiver bean is called.
      Result: com.fasterxml.jackson.databind.exc.InvalidDefinitionException that a message cannot be converted to a Listener. (Trying to call the method which returns a Bean.)

      Attachments

        Activity

          People

            grussell Gary Russell
            nick.stolwijk Nick Stolwijk
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: