I have a scenario wherein the main thread is running the flyway migrations. In one of the migration scripts, we are sending a message to the JMS queue. This activates the JMS listener thread to process the message which in turn calls the service layer. Therefore executing flyway migration which then conflicts with the main thread. Hence I want to make sure that the listener thread should only call the service layer once all the migrations are completed by the main thread. Is there a way to achieve this.? Currently I am making the listener thread to sleep for few seconds. But I don't think this would be solution going forward.
Asked
Active
Viewed 494 times
1 Answers
0
Set autoStartup
to false
on the listener container factory.
When using boot, there is a property https://docs.spring.io/spring-boot/docs/current/reference/html/application-properties.html#application-properties.integration.spring.jms.listener.auto-startup
You can then start the container(s) using the JmsListenerEndpointRegistry
bean. registry.start()
to start all containers or you can get each container and start them individually.

Gary Russell
- 166,535
- 14
- 146
- 179
-
I cannot set this property because all the other listeners will be affected. Is there any way that only this particular listener thread resumes once after the main thread completes migration. I was thinking whether it can be done by using a @PostConstruct. Not sure though. – Geeky Jun 01 '22 at 17:22
-
You can use a different container factory for just this one listener and use the default one for all the others. – Gary Russell Jun 01 '22 at 17:26
-
But I want to start this container only after all the flyway migrations have run. How will I know that? – Geeky Jun 03 '22 at 08:05
-
I suggest you ask a new question with that as the the subject. This one is about starting the listener. – Gary Russell Jun 03 '22 at 13:07