Search code examples
spring-bootspring-cloudamazon-sqsspring-messaging

How to use a Spring @MessageMapping from properties to set an annotation attribute


I'm working with SQS spring-boot:spring-cloud, I want to externalize the parameter, retrieve the value based on the active profile

@MessageMapping("static.queue")
public void receiveMessage(Payload payload) {
  // ...
}

is there any way to solve this problem?

something like

@MessageMapping("${properties.dynamic}")
public void receiveMessage(Payload payload) {
  // ...
}

Solution

  • I would try two options:

    1. Use project spring-could-aws. You can annotate your SQS queue listener with @SqsAnnotation.
    2. Use JMS interface to access SQS queues. In such case you can use plain Spring JMS features (e.g. @JmsListener).
    3. @MessageMapping have support for expressions in MessageMapping annotation:

    public class Example {

    @MessageMapping("${spring.app}")
    public void receiveMessage(Payload payload)  {
        // do
    }}
    

    in yml file:

    spring:
      profiles: prod
      app: 'queueName1'
    
    spring:
      profiles: dev
      app: 'queueName2'