activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mathew Phillips <mathew.phill...@wartburg.edu>
Subject RE: ActiveMQ consume message even with error
Date Tue, 24 Aug 2010 23:16:39 GMT
Thank you for the link. Basically what I gathered from it was that I should send it to some
sort of error queue. But since its an MDB i would have to implement the ability to put a message
onto a queue in order
to get rid of the message. Is there a simpler way to just remove the message from the queue
without having to go into the admin console and purge it manually?
________________________________________
From: Timothy Bish [tabish121@gmail.com]
Sent: Tuesday, August 24, 2010 5:50 PM
To: users@activemq.apache.org
Subject: Re: ActiveMQ consume message even with error

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/


Mime
View raw message