2 Replies Latest reply on Apr 8, 2009 3:03 AM by Vikas Gupta

    Sending Messages from EJB using container transaction

    Vikas Gupta Newbie

      Hello Everyone,

      We have a requirement to send thousands of messages using EJB in a day. Thus every time a need arises to send a message, we have a dedicated session bean which will post message to the queue as part of EJB (container) transaction. We are using JBoss EAP 4.3.0.
      Our question is what will be the right connection factories to use. Currently we are using /ConnectionFactory to send messages but it seems that it does not uses container transaction. If we use session transacted session it sends message only if we explicitly commit the transaction and it seems to have two transactions running in parallel i.e. container transaction & JMS transaction which are independent of each other. Thus we used session transacted as false and AUTO_ACK true but with this we face another problem that messages are delivered to consumer even before the EJB i.e. container transaction finishes. Thus regardless the originating transaction was successful, complete or failed, the message is delivered to consumer which gives unreliable results

      Our requirement is that message should be delivered to consumer only if the originating EJB transaction was successful else the message posted should be de-queued. The whole infrastructure should be fast to process the message.
      We want to know what will be the most appropriate approach to get best performance and reliability

      1. Which connection factory to use so that JMS uses Container transaction? Currently we are using /ConnectionFactory
      2. Do we need to open connection every time we send a message or we can have a connection object initialized in post construct of Session bean. Currently we create it at post construct of session EJB
      3. Do we need to create session every time we send a message or we can have a session object initialized in post construct of Session bean. Currently we create it every time.
      4. What all points should we take care from performance tuning perspective. We are using MS-SQL Server 2005.


      Best Regards,
      Abhishek

        • 1. Re: Sending Messages from EJB using container transaction
          Frank Schwarz Newbie

           

          "eontech" wrote:

          1. Which connection factory to use so that JMS uses Container transaction? Currently we are using /ConnectionFactory

          java:/JmsXA

          "eontech" wrote:

          2. Do we need to open connection every time we send a message or we can have a connection object initialized in post construct of Session bean. Currently we create it at post construct of session EJB

          From a JMS point of view, the connection object is thread safe. It should therefore be safe to put it to an instance variable of your EJB

          "eontech" wrote:

          3. Do we need to create session every time we send a message or we can have a session object initialized in post construct of Session bean. Currently we create it every time.

          There is a correlation between session and transcation, furthermore the session object has not be thread-safe. So, you should create it for every transaction.

          Kind regards,
          Frank


          • 2. Re: Sending Messages from EJB using container transaction
            Vikas Gupta Newbie

            Thank you very much Frank for your response.

            We want to know if using java:JmsXA won't affect the performance or what would be the performance impact if we use this factory.

            Best Regards,
            Abhishek