To do a receive you will need to call start() on the connection. Otherwise, messages will not be delivered. The reason the MDB works is because this is done automagically under the hood for you.
Thank you for this helpful reply.
I added method start() at the begining and stop() method at the end. But that was not a good move. I received Exception:
javax.jms.IllegalStateException: This method is not applicable inside the application server. See the J2EE spec, e.g. J2EE1.4 Section 6.6
When i removed method stop() everything works fine.
consumer.close(); session.close(); //con.stop(); con.close(); ictx.close();
Thanks again. I would have lost much more time if i had not been told what is wrong.
What happens with Connection.start() ?
With connection.start() everything works fine.
Connection con = cf.createConnection(); con.start(); //new line Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
I had some problems when i added connection.stop() method to my code.
So i removed stop() method call, and again everything works corectly.