Discussions

General J2EE: How to send a transaction secure asynchronous message?

  1. How to send a transaction secure asynchronous message? (3 messages)

    Problem:
    I am writing a method in a session bean with the TX_REQUIRED property set. At the end of the method i would like to post a message to a jms server. If afterwards the transaction fails, than the message will still be delivered. This i understand but can not accept.
    My Solution:
    Certainly i could put
    the code of sending the message in another method which will be called afterwards by the client or
    i could try to commit the transaction explicitly before sending the message ( even though i do not know how to).
    My Question:
    Both of the above is not satisfying. Rather i would like some "transaction secure" message queue meanig the message will only be posted if the transaction has taken place. Does such a thing exist? Thank you in advance for the concern.
  2. I'm not sure I understand your question, but let us look at this scenario:

    void method() {
      do stuff
      send JMS message
    }

    If the transaction method() ran in fails at any point, the JMS message will not be delivered. When JMS connections are transacted (which is the case in EJB), all the messages you send in a transaction are kept in a local buffer, and are not delivered to their destination. Similarly all messages you recieve are not acknowledged. When the transaction commits all the outgoing buffer is flushed and the incoming messages are acknowledged. If the transaction rolls back, nothing gets sent and all the messages you recieved are scheduled for redelivery.
    Does this solve your problem? Or am I not getting your question?

    Gal
  3. Gal

    Is this also true in EJB 1.1 (for publishing messages of course)...??

    We will be using WAS 4.0 and it doesn't support EJB 2.0 yet
    from what I understand. We would still gain advantage from using JMS to publish from our EJB's. The transactional support of buffering the messages until commit would solve some problems...

    Thanks
    AJD
  4. hmm..
    if i get your ? right...

    methodA(){
    some transaction..
    }

    after transaction send message..
    if this is so
    boolean methodA(){
    if(logic)
    return true;
    else return false
    }

    if(methodA()){
    send message()
    }