0

I am attempting to use an MDB (onMessage) to run a long running JDBC sql query and export the output to disk.

I am running into timeouts with the onMessage because the acknowledge takes place after the successful completion of the onMessage. Ideally I would like to immediately acknowledge the message as the handling of the work (JDBC query export) has its own retry/error handling built in.

Is there an approach with MDB onMessage that will allow for this immediate acknowledgement or some better way of handling the async run of a long running process within the Java EE space.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Bill Pfeiffer
  • 926
  • 8
  • 20
  • This question mentions JDBC and SQL, but does it have anything to do with Microsoft Access? (The "mdb" tag is currently defined as an alias for "ms-access" and is automatically converted.) – Gord Thompson May 13 '13 at 17:31
  • My bad, the mdb is for Message Driven Bean. I'll attempt to update the the tags. Thanks! – Bill Pfeiffer May 13 '13 at 18:27

1 Answers1

0

You can acknowledge the message manually using TransactionManagementType.BEAN:

@MessageDriven
@TransactionManagement(TransactionManagementType.BEAN)
public class TestMDB implements MessageListener {
    @Resource
    UserTransaction tx;

    @Override
    public void onMessage(Message msg) {
        String txt="";
        try {
            tx.begin();     
            TextMessage txtMsg = (TextMessage) msg;
            txt = txtMsg.getText();
            tx.commit();
        } catch (Exception e) {
            try {
                tx.rollback();
            } catch (Exception e1) {
                //....
            }
        }
        // call some EJB transactional method 
        // or
        try {
            tx.begin();
            //do some db stuff
            tx.commit();
        }catch(Exception e){
            //...
        }
    }
}
rzymek
  • 9,064
  • 2
  • 45
  • 59