@Component
public class MyJmsListener{
@Autowired
private MyService myService;
@JmsListener(destination="${queue.nameOne}")
void receiveMessageOne(Message message){
myService.process(message);
}
@JmsListener(destination="${queue.nameTwo}")
void receiveMessageTwo(Message message){
myService.process(message);
}
@JmsListener(destination="${queue.nameThree}")
void receiveMessageThree(Message message){
myService.process(message);
}
}
**I have tried with @Conditional(demoClass implements Condition) annotation which will make the bean based on my demoClass and the bean was created . The problem is MyJmsListener class has three @JmsListener, if i would not make bean of MyJmsListener class , so all my @JmsListener will deacivate . **My query is to stop and start @JmsListener based on some codition in Spring Boot.
My understanding is that you want MyJmsListener to stop/start listening on the queues based on a property. For this you can use ConditionalOnProperty like below:
@ConditionalOnProperty(prefix = "jms", name = "enabled", havingValue = "true")
You have to declare jms.enabled=true and you will get the on off switch you require.
In case you need to switch between queues and listen to just one at a time then you need to split them in 3 different beans and have them starting based on a property similar to above.
To do this programatically then you can use JmsListenerEndpointRegistry
You can create something similar to start the app.