ejb-3.0wildfly-10message-driven-bean

how can i do for an MDB to deploy last on my wildfly


What is happening to me is that the MDB receives messages and tries to process them and even my server has not started completely

any idea how to solve this?


Solution

  • You can find out if your server startup is completed by one of the following two techniques:

    1. use ServletContextListener, once your application deployment is complete, server would call ServletContextListener.contextInitialized method
    2. Use mbean support from wildfly, you can query mBean via JMX interface of wildfly and figure out if the server state is 'started'. But mind you, your code would be tied down to wildfly only in this case.

    Once you decide the option to figure out the server startup state, you need to check for it in your MDB's postconstruct method and go ahead only if the server is started.

    @MessageDriven(...)
    public class MyMdb implements MessageListener {
        @PostConstruct
        public void init() {
            // check if server has started here 
            //if server is not started, sleep and re-check again.
        }
    
        public void onMessage(Message message) {
    
        }
    }