9 Replies Latest reply on Dec 11, 2005 11:56 PM by vichandoko

    Use JCA or IL? (java:/JmsXA or java:/XAConnectionFactory)

      Hello.

      This question is about JMS (+XA).

      I cannot seem to find a definate answer to "which connection factory
      i should be using when trying to use JMS (+XA) from inside my beans".

      Here is what i've found so far in the wiki & docu

      JBossJMSRA (http://www.jboss.org/wiki/Wiki.jsp?page=JBossJMSRA)
      - It can be used from the Servlet? and EJB containers.
      - Automatic Transaction enlistment
      - binds the ConnectionFactory at java:/JmsXA

      ConfigJBossMQIL (http://www.jboss.org/wiki/Wiki.jsp?page=JBossJMSRA)
      - The connectors allow the clients to connect with JBossMQ
      - JVM - an in memory connector that avoids network transport
      - bind two connection factories into JNDI
      - java:/ConnectionFactory
      - java:/XAConnectionFactory

      JBossBook323 p337, p360

      What i think i understand:
      1) The JVMIL can only be used inside JBoss...so beans for example.
      2) There are two types of ConnectionFactories involved here, JCA and JMS.
      3) Using the JCA flavour i get pooling of connections
      4) The other invokation layers are primarily there for external clients.
      (ie UIL2 uses socket comms)

      Q1) I want to use use JMS in my beans and want them to be enlisted in
      my XA tx. How do i decide whether to use:

      - java:/JmsXA or
      - java:/XAConnectionFactory

      Q2) What are the differences between using the JCA and IL
      ConnectionFactories...especially w.r.t XA tx.

      cheers

        • 1. Re: Use JCA or IL? (java:/JmsXA or java:/XAConnectionFactory
          genman


          Adrian always suggests using "java:/JmsXA" which is the pooled connection factory provider. java:/XAConnectionFactory might also work, but I think the JmsXA is definitely going to work with your transaction.

          JCA is a connection interface and IL is the invocation layer, the transport mechanism. With java:/JmsXA I believe you get java:/XAConnectionFactory connections, but they are going to be pooled for you.

          • 2. Re: Use JCA or IL? (java:/JmsXA or java:/XAConnectionFactory

            Thanks for the tips.

            I'm also aware of Adrian suggesting "java:/JmsXA". I just can't seem to find any reasons.


            java:/XAConnectionFactory might also work...

            I really am trying to find out if it is:
            - meant to work
            - does actually work
            - how and when it should be used

            java:/JmsXA I believe you get java:/XAConnectionFactory connections

            That would mean there is a link between the files:
            - jms-ds.xml and
            - jvm-il-service.xml

            jvm-il-service.xml
            ...
            <attribute name="ConnectionFactoryJNDIRef">java:/ConnectionFactory</attribute>
            <attribute name="XAConnectionFactoryJNDIRef">java:/XAConnectionFactory</attribute>
            ...
            


            jms-ds.xml
             <mbean code="org.jboss.jms.jndi.JMSProviderLoader"
             name="jboss.mq:service=JMSProviderLoader,name=JBossMQProvider">
            ...
             <attribute name="QueueFactoryRef">java:/XAConnectionFactory</attribute>
             <attribute name="TopicFactoryRef">java:/XAConnectionFactory</attribute>
             </mbean>
            


            Is this how they are related?
            the "<tx-connection-factory>" (in jms-ds.xml) does not seem to define what type of connections it is handing out?

            I would be very grateful for any insights into these and the original questions. Should i reformulate my questions? I am still searching FAQ, Wiki, Docu....

            cheers

            • 3. Re: Use JCA or IL? (java:/JmsXA or java:/XAConnectionFactory

              The jms-ds.xml shipped with 3.2.4+
              makes the relationship explicit as does the FAQ and WIKI.

              • 4. Re: Use JCA or IL? (java:/JmsXA or java:/XAConnectionFactory

                Thanks for the response.
                I assume it is only refering to my very last question relating to the type
                of connections the <tx-connection-factory> dishes out. I found the reference
                in the faq. That question should not have slipped out.

                However, the original questions (Q1 & Q2) and the followup question regarding the use
                of java:/XAConnectionFactory still remain unanswered.
                I would be very grateful if you could shed some light on them.

                I've tried to be as clear as possible about where i've looked and what i understand
                and what my question is...i have no stack trace. I'm trying to understand.
                I'll happily contribute to the wiki/faq once i do.



                I went through the faq & wikis again. Here is what i found:

                Main FAQ (http://www.jboss.org/wiki/Wiki.jsp?page=JBossFrequentlyAskedQuestions)
                -nothing related

                FAQJBossMQ (http://www.jboss.org/wiki/Wiki.jsp?page=FAQJBossMQ)

                HowDoIMakeJMSWorkInJTATransaction
                - http://www.jboss.org/wiki/Wiki.jsp?page=HowDoIMakeJMSWorkInJTATransaction
                - just says use java:/JmsXA

                HowDoIConfigureTheJMSResourceAdapterToUseARemoteConnectionFactory
                - http://www.jboss.org/wiki/Wiki.jsp?page=HowDoIConfigureTheJMSResourceAdapterToUseARemoteConnectionFactory
                - I assume this is what you were referring to :
                (link between <tx-connection-factory> and <mbean code="org.jboss.jms.jndi.JMSProviderLoader")

                 <config-property name="JmsProviderAdapterJNDI" type="java.lang.String">
                 java:/WhateverJMSProvider
                 </config-property>


                This only answers my question "the <tx-connection-factory> (in jms-ds.xml)
                does not seem to define what type of connections it is handing out?"

                Wiki - JBossMQ (http://www.jboss.org/wiki/Wiki.jsp?page=JBossMQ)

                JBossMQXA
                - http://www.jboss.org/wiki/Wiki.jsp?page=JBossMQXA
                - ?

                JBossJMSRA
                - http://www.jboss.org/wiki/Wiki.jsp?page=JBossJMSRA
                - referenced in original post

                JBossMQIL
                - http://www.jboss.org/wiki/Wiki.jsp?page=JBossMQIL
                - just tells me what the docu says

                ConfigJBossMQIL
                - http://www.jboss.org/wiki/Wiki.jsp?page=ConfigJBossMQIL
                - referenced in original post



                • 5. Re: Use JCA or IL? (java:/JmsXA or java:/XAConnectionFactory

                  Your question is should you use the resource adaptor or a plain connection:

                  http://www.jboss.org/wiki/Wiki.jsp?page=IWantToConnectToXYZShouldIUseJCA

                  JMS like databases are "legacy" systems.

                  • 6. Re: Use JCA or IL? (java:/JmsXA or java:/XAConnectionFactory

                    So the question was asked wrong?

                    Assumption: All the ConnectionFactories we are talking about are dishing out javax.jms.Connection objects.

                    Perhaps my confusion is related to the fact that we have Connections and Connection factories in both JCA and JMS worlds?

                    ok, so you are saying (trying to answer the questions in the original post)

                    A1) If you want the benefits that come from using a ResourceAdaptor (xa, security, pooling) use java:/JmsXA to obtain a jms connection object.

                    If not, use java:/XAConnectionFactory (defined in jvm-il-service.xml) to obtain a "plain" jms connection object. Q3) This won't do xa because we're not using the ResourceAdaptor???

                    A2) The differences between the connection factories defined/declared in jms-ds.xml and jvm-il-service.xml still remain unclear. For example they both contain the JNDI name java:/XAConnectionFactory. Q4) Who is binding what into JNDI?

                    jms-ds.xml
                    docu p359 "The JNDI name under which the provider javax.jms.QueueConnectionFactory
                    will be bound."

                    [JMSProviderLoader] <----JmsProviderAdapterJNDI------ [tx-connection-factory]
                     |
                     +---QueueFactoryRef----> java:/XAConnectionFactory
                    


                    jvm-il-service.xml
                    docu p337 "The JNDI location that this IL will bind a ConnectionFactory setup to use this IL."
                    [JVMServerILService]
                     |
                     +---ConnectionFactoryJNDIRef----> java:/ConnectionFactory
                     |
                     +---XAConnectionFactoryJNDIRef----> java:/XAConnectionFactory
                    


                    They can't both bind something to the same name, so one of them must be referencing the other. My guess is that the [JMSProviderLoader] is referencing the ConnectionFactory defined by the
                    [JVMServerILService] who is responsible for binding it into JNDI. Q5)Is this correct?

                    If the relationship between the RA and IL is perfectly clear then it should be pretty simple to explain. Please.

                    • 7. Re: Use JCA or IL? (java:/JmsXA or java:/XAConnectionFactory

                      Anyone? Adrian?

                      • 8. Re: Use JCA or IL? (java:/JmsXA or java:/XAConnectionFactory
                        penguine

                        the jvm-il don´t use the global namespace.
                        to use jvm-il "java:/ConnectionFactory" not "ConnectionFactory"

                        • 9. Re: Use JCA or IL? (java:/JmsXA or java:/XAConnectionFactory
                          vichandoko

                          i am using JBOSS 3.2.3
                          (please dont rush me to upgrade, we are using this in operational mode, so huge testing to be done for migration)

                          Am confused by the same issue. Would the following code do in order for the publish of message to Topic to be part of transaction.

                          ---------------------------------------------------------------------------------
                          try{
                          TopicConnectionFactory qcf = (TopicConnectionFactory)
                          (new InitialContext().lookup("java:/JmsXA"));
                          TopicConnection conn;
                          conn = qcf.createTopicConnection();
                          Topic queue = (Topic) (new InitialContext().lookup("topic/"+topicName));
                          TopicSession session = (TopicSession)
                          conn.createTopicSession(true, TopicSession.AUTO_ACKNOWLEDGE);

                          TopicPublisher send = session.createPublisher(queue);
                          MapMessage message = session.createMapMessage();
                          message.setString("action", action);

                          Enumeration keys = param.keys();
                          while(keys.hasMoreElements()){
                          String key = (String) keys.nextElement();
                          message.setObject(key, param.get(key));
                          }
                          send.publish(message);

                          send.close();
                          session.close();
                          conn.close();
                          }catch(JMSException e1){
                          StringBuffer log = new StringBuffer();
                          log.append("Error during publishing of message to Topic: ");
                          log.append(topicName);
                          log.append(", for action: ");
                          log.append(action);
                          logger.error(log.toString(), e1);
                          } catch (NamingException e) {
                          StringBuffer log = new StringBuffer();
                          log.append("Error during publishing of message to Topic: ");
                          log.append(topicName);
                          log.append(", for action: ");
                          log.append(action);
                          logger.error(log.toString(), e);
                          }
                          ----------------------------------------------------------------------------------

                          The whole process i would like to achieve is as follows:
                          1. Servlet to Call on SessionBean to perform operations including database write.
                          2. SessionBean call on utility class to publish Message to a Topic. Utility class is normal bean. And the above contain in utility class.
                          3. MDB used as listener to the Topic. MDB will perform operations including retrieval of data written in Step 1.

                          I've initially use 'ConnectionFactory' instead of 'java:/JmsXA'. It caused problem because occasionally, during Step 3, the data retrieved wasnt the most up-to-date that has been commited in Step 1.

                          After much ploughing through the forum, i've change the codes to the above.

                          Would anyone mind to shed some light whether the above would solve my problem? It's a little hard to replicate the problem due to the random nature. Thus am not completely sure whether i've fixed the error.

                          Thanks much.

                          Veny