0

The following class handle the messages receive on a Rabbit MQ channel:

@RabbitListener(queues=RabbitMQConfiguration.QUOTE_REQUEST_QUEUE)
public class QuoteRequestHandler {

    @Autowired
    private SimpMessageSendingOperations messagingTemplate;

    @RabbitHandler
    public void handle(String request) {
        QuoteChannelServiceImpl.getInstance(messagingTemplate);
    }

}

I'd like to have access to SimpMessageSendingOperations inside this class, but as it is not a spring bean, it'd be null. I'm wondering if there is a clean way to inject this dependency into this class.

Arian
  • 7,397
  • 21
  • 89
  • 177
  • Why don't you make it spring bean? AFAIK `@RabbitListener` won't work if it is not spring bean. – talex Nov 09 '18 at 06:16
  • Possible duplicate of [How to add POJO to Spring context to enable injecting dependencies?](https://stackoverflow.com/questions/39353019/how-to-add-pojo-to-spring-context-to-enable-injecting-dependencies) – talex Nov 09 '18 at 06:19
  • @talex I checked for few examples and I cannot confirm what you said, e.g. https://www.rabbitmq.com/tutorials/tutorial-two-spring-amqp.html – Arian Nov 09 '18 at 07:07
  • In your example `ReceiverConfig` class add `Tut2Receiver` to spring context. – talex Nov 09 '18 at 07:09
  • If I annotate it with `@Service` does it mean it will be in Singleton scope and for all message in the queue, the same handler will be used? – Arian Nov 09 '18 at 07:11
  • And is it normally how rabbit listener seems to work? – Arian Nov 09 '18 at 07:11
  • 1
    Yes for both questions. – talex Nov 09 '18 at 07:14

0 Answers0