7 Replies Latest reply on Sep 4, 2002 2:30 AM by Craig Brown

    Asynchronous send within Session EJB to queue with MDB liste

    Craig Brown Newbie

      Is it possible to asynchronously send a message from within a Session EJB to a queue that is being listened to by an MDB?

      It seems that when sending a message from within a Session EJB to a JMS queue with an MDB listening for incoming messages, that the send is NOT asynchronous.

      When using createQueueSession(false,Session.AUTO_ACKNOWLEDGE), the Session bean does not receive an acknowledgement allowing the Session EJB to proceed until after the MDB onMessage method has completed. The onMessage call can take several minutes to complete. Whether the onMessage call is successful has no bearing on the acknowledgement. This is not an acceptable solution in our case because the Session EJB is blocked for a substantial time. We want the Session EJB to be able to proceed once the message is queued, regardless of when it is processed.

      Any help would be greatly appreciated.

        • 1. Re: Asynchronous send within Session EJB to queue with MDB l
          Craig Brown Newbie

          I forgot to mention that we have also tried using createQuoteSession(true, 0), as suggested in the Sun JMS Tutorial. Subsequent calls to send messages return quickly with no Exceptions or Errors thrown, however the message sent never arrives in the queue and therefore is never processed by the MDB.

          • 2. Re: Asynchronous send within Session EJB to queue with MDB l
            Andreas Schaefer Apprentice

            Hi

            You second part does not work because I guess you are using a regular Connection Factory. But these are not added to the EJB transaction context so the transaction rollsback after a while. So you can either call commit() on the session or you have to use "java:/JmsXA" connection factory.

            On the other hand please let me know which version you are using and which OS.

            Have fun - Andy

            • 3. Re: Asynchronous send within Session EJB to queue with MDB l
              Craig Brown Newbie

              Thanks for the response. We are using JBoss 3.0.0 on both Windows 2000 with Sun JRE 1.3.1 and Redhat Linux with IBM JRE 1.3.0. We plan on moving to JBoss 3.0.1 in the near future.

              When you refer to the second part, I am assuming you mean using createQueueSession(true, 0), which as I understand it is the method we should be using to asynchronously send to a queue. It makes sense we would need to use the XAConnectionFactory. However, wouldn't it make sense for some sort of Error or Exception to be thrown when trying to make a connection that is not allowed from within an EJB? Our code happily chugs along although the message never arrives at the queue.

              I will follow up with the results of using the XAConnectionFactory.

              • 4. Re: Asynchronous send within Session EJB to queue with MDB l
                Craig Brown Newbie

                Thanks for the response. We are using JBoss 3.0.0 on both Windows 2000 with Sun JRE 1.3.1 and Redhat Linux with IBM JRE 1.3.0. We plan on moving to JBoss 3.0.1 or later in the near future.

                When you refer to the second part, I am assuming you mean using createQueueSession(true, 0), which as I understand it is the method we should be using to asynchronously send to a queue. It makes sense we would need to use the XAConnectionFactory. However, wouldn't it make sense for some sort of Error or Exception to be thrown when trying to make a connection that is not allowed from within an EJB? Our code happily chugs along although the message never arrives at the queue.

                I will follow up with the results of using the XAConnectionFactory.

                • 5. Re: Asynchronous send within Session EJB to queue with MDB l
                  Colin Yates Newbie

                  I have done this using the following:

                  Have an interface IOperation with a method called "doOperation()".

                  Have a MDB which listens to a queue and assumes that he ObjectMessage is IOperation. This MDB will then call IOperation.

                  In the session bean, create an instance of IOperation to do what you want and place it on the message queue. The session bean will *only* wait for the bean to be placed on the queue, not the execution of the bean.

                  I then have a seperate class called OperationResult which the MDB passes into IOperation.doOperation which is then placed on the replyQueue but that is optional.

                  It really does work and is a very simple way of introducing asynchronous behaviour. I use it for logging where the user visits.

                  Hope this helps

                  • 6. Re: Asynchronous send within Session EJB to queue with MDB l
                    Andreas Schaefer Apprentice

                    Hi

                    The ussage of a "client" ConnectionFactory is allowed within an application server like the direct usage of a JDBC Connection without using a DataSource (even this is not recommended). So no need to throw an exception.
                    In J2EE it is important that people understand the underlying framework but I agree the EJB 2.0 spec. is not very clear on this either.

                    I will see that this is mentioned in the Quick Start Guide.

                    Have fun - Andy

                    • 7. Re: Asynchronous send within Session EJB to queue with MDB l
                      Craig Brown Newbie

                      Thanks again for the responses.

                      Indeed, using the "java:/JmsXA" ConnectionFactory solved the problem.

                      Some mention of the JmsXA ConnectionFactory in the Quick Start Guide would have been a help to me, and I'm sure would help others in the future. I also have the JBoss Administration and Development Guide, which does not specifically address this topic. I think an example using the JmsXA ConnectionFactory in the JMS chapter would be very useful. I would be happy to contribute this example.