0

I am publishing a message into the JMS queue as part of one of the flyway migration scripts. Once the message is published, the JMS Listener thread immediately tries to process the message by executing flyway migrations. But this is leading to a conflict wherein both the main thread and the listener thread are trying to execute the same flyway migration. Is there a way to determine as to when all the flyway migrations are complete so that I can then start the listener thread to process the messages?

One solution which is mentioned in How do I stop the JMS Listener thread until the spring is completely initialized: I've created a seperate JMS Container Factory with autoStartup = False and assigned it to the JMS Listeners which are taking part in flyway migrations. But inorder to start the listeners, how do I know that flyway migrations are complete?

Geeky
  • 113
  • 9

1 Answers1

0

You could try triggering something using an afterMigrate callback.

If you're using Teams edition you could use a script callback, otherwise you could implement a Java callback that supports the AFTER_MIGRATE event, e.g:

package db.callback;

import org.flywaydb.core.api.callback.Callback;
import org.flywaydb.core.api.callback.Context;
import org.flywaydb.core.api.callback.Event;

public class AfterMigrateCallback implements Callback {
    @Override
    public boolean supports(Event event, Context context) {
        return event.equals(Event.AFTER_MIGRATE);
    }

    @Override
    public boolean canHandleInTransaction(Event event, Context context) {
        return false;
    }

    @Override
    public void handle(Event event, Context context) {
        /*
        Some code to tell the rest of the app the migration is complete
         */
    }

    @Override
    public String getCallbackName() {
        return "After Migrate";
    }
}

and add it as a .jar somewhere in a classpath location.

Tom Smith
  • 111
  • 2