On Tue, 2010-08-24 at 22:35 +0000, Mathew Phillips wrote: > I have an MDB that i developed to consume messages from a queue and write the > data to a database. It works fine as long as no errors are thrown in the > onMessage method of the mdb. But if an exception is thrown > the message is not consumed from the queue. Is there a way to > programmatically consume the message even if an error occurs? > > class MyMDB implements MessageListener{ > .... > public void onMessage(Message message) { > TextMessage txtMsg = (TextMessage)message; > try { > Connection dbconn = ds.getConnection(); > String[] data = txtMsg.getText().split(","); > PreparedStatement stmt = dbconn.prepareStatement( > "INSERT INTO CUSTOMER_TBL > values(?,?,?)"); > stmt.setInt(1,Integer.parseInt(data[0])); > stmt.setString(2,data[1]); > stmt.setString(3,data[2]); > stmt.execute(); > dbconn.close(); > } catch (Exception e) { > carmdb_logger.error("Error inserting to database",e); > } > ... > } > > Thanks, > Matt Phillips
See this article for a discussion of why you should handle all errors in the onMessage method and not propagate them to the JMS client code. http://effectivemessaging.blogspot.com/2009/01/messagelistener-exception-handling.html Regards -- Tim Bish Open Source Integration: http://fusesource.com ActiveMQ in Action: http://www.manning.com/snyder/ Follow me on Twitter: http://twitter.com/tabish121 My Blog: http://timbish.blogspot.com/