Search code examples
error-handlingjmsejbjms-topicedb

How to catch error when message have been sent from JMS


I am sending an message through my standalone application that uses EJB MDB to communicate to my other application server that is running on JBOSS server.My application server is connected to a MSSQL server. In certain scenario, connection to the database is lost on application server side and we get following error -

Connection is reset.

Later , when i try to send message i don't get any error at my standalone EJB MDB logs and the process just stops executing.I get error log on application server side logs but same logs don't get propagated to my EJB MDB error logs.

As per my understanding, when db connection is lost all the ejb bean present in jboss container get nullified too.(I could be wrong here, i am new to EJB).

I tried implementing below code in my code that use to send message -

QueueConnection qcon = null;
   @PostConstruct
    public void initialize() {
        System.out.println("In PostConstruct");
        try {
            qcon = qconFactory.createQueueConnection();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    @PreDestroy
    public void releaseResources() {
        System.out.println("In PreDestroy");
        try {
            if(qcon != null)
            {
                qcon.close();
            }
            if(qcon== null){
                throw new Exception(" new exception occured.");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

I was in a impression that Queueconnection object will be nullified, when our db connection have been lost(as we are creating bean and making connection for message). But it doesn't seem to work.


Solution

  • I did found a way to call back my application after sending message. I used a separate temporary queue and used setJMSReplyTo method to set the reply destination. More info could be obtained from this link. Hope this helps others.