I am trying out Spring Boot and ActiveMQ, and have been able to get things "working". But, I'd like to be able to dynamically set the destination for a JmsListener, and am failing spectacularly.
This code (not surprisingly) works...
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
@Component
public class MsgReceiver {
@JmsListener(destination = "Consumer.myConsumer1.VirtualTopic.TEST-TOPIC")
public void receiveMessage(String strMessage) {
System.out.println("Received -> " + strMessage);
}
}
So does this code (because Spring is okay with a String constant?)...
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
@Component
public class MsgReceiver {
private final String consumer = "Consumer.myConsumer.VirtualTopic.TEST-TOPIC";
@JmsListener(destination = consumer)
public void receiveMessage(String strMessage) {
System.out.println("Received -> " + strMessage);
}
}
But, this code does not work...
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
@Component
public class MsgReceiver {
private String consumer;
public MsgReceiver() {
consumer = "Consumer.myConsumer.VirtualTopic.TEST-TOPIC";
}
@JmsListener(destination = consumer)
public void receiveMessage(String strMessage) {
System.out.println("Received -> " + strMessage);
}
}
I understand that Spring is not liking the non-constant value (I am guessing that this has to do with how the annotations get expanded at runtime?). I also understand that I could do something like:
@JmsListener(destination="${consumer}")
with the value being provided in an application.properties file. However, I'm trying to work towards a final solution where the consumer value is set using something like...
consumer = SomeConfigUtil.getValueForKey("foo");
Is there a way to get this to work? Or, is there a better way to achieve my objective?
Add Note: I have seen the examples using "straight JMS" to manage all of this, but have to admit that the annotations in Spring Boot make it much simpler. However, it's looking like hand-rolling things with "just JMS" might be the only solution?