9 Replies Latest reply on Feb 2, 2012 10:13 AM by vinnetus

    MDB with Oracle AQ via Sun Adapter

    ryandavid

      I have integrated Oracle AQ with JBoss 4.0.2 using the rar of Sun Adapter. I can send messages to a queue but I have some problems in using an MDB that reads from a queue.

      The MDB is BMT because the adapater doesn't support XA connections.

      I used this ejb-jar.xml

      <ejb-jar>
      <enterprise-beans>
      
       <message-driven>
       <ejb-name>TestJMSBean</ejb-name>
       <ejb-class>it.senato.testjms.TestJMSBean</ejb-class>
       <messaging-type>javax.jms.MessageListener</messaging-type>
       <transaction-type>Bean</transaction-type>
      
       <activation-config>
       <activation-config-property>
       <activation-config-property-name>destinationType</activation-config-property-name>
       <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
       </activation-config-property>
      
      
       <activation-config-property>
       <activation-config-property-name>destinationProperties</activation-config-property-name>
       <activation-config-property-value>owner=senaprod,name=FROM_QUEUE</activation-config-property-value>
       </activation-config-property>
       <activation-config-property>
       <activation-config-property-name>connectionFactoryProperties</activation-config-property-name>
       <activation-config-property-value>jdbc_connect_string=jdbc:oracle:thin:scott/mypass@myhost:1521:svil,host=senadbmssvil,user=scott,password=mypass,port=1521,sid=svil,driver=thin</activation-config-property-value>
       </activation-config-property>
      
       <activation-config-property>
       <activation-config-property-name>userName</activation-config-property-name>
       <activation-config-property-value>scott</activation-config-property-value>
       </activation-config-property>
       <activation-config-property>
       <activation-config-property-name>mypass</activation-config-property-name>
       <activation-config-property-value>svil</activation-config-property-value>
       </activation-config-property>
      
       </activation-config>
      
       </message-driven>
      
       </enterprise-beans>
      
       <assembly-descriptor>
       </assembly-descriptor>
      
      </ejb-jar>


      this jboss.xml

      <jboss>
       <enterprise-beans>
      
       <message-driven>
       <ejb-name>TestJMSBean</ejb-name>
      
       <invoker-bindings>
       <invoker>
       <invoker-proxy-binding-name>message-inflow-driven-bean</invoker-proxy-binding-name>
       </invoker>
       </invoker-bindings>
      
       <resource-adapter-name>oracleaq.rar</resource-adapter-name>
      
       </message-driven>
       </enterprise-beans>
      </jboss>
      


      and finally this is the onMessage() method

       public void onMessage(Message msg) {
       try {
       ctx.getUserTransaction().begin();
      
       logger.debug("onMessage...");
       // extract message
       TextMessage textMessage = null;
       try {
       textMessage = (TextMessage) msg;
      
       } catch (ClassCastException ce) {
       logger.warn("Received a non TextMessage");
       ctx.getUserTransaction().commit();
       return;
       }
      
       logger.info("Received a text message: " + textMessage.getText());
       msg.acknowledge();
       ctx.getUserTransaction().commit();
      
       } catch (NotSupportedException e) {
       logger.error(e.getMessage(),e);
       } catch (SystemException e) {
       logger.error(e.getMessage(),e);
       } catch (JMSException e) {
       logger.error(e.getMessage(),e);
       } catch (RollbackException e) {
       logger.error(e.getMessage(),e);
       } catch (HeuristicMixedException e) {
       logger.error(e.getMessage(),e);
       } catch (HeuristicRollbackException e) {
       logger.error(e.getMessage(),e);
       }
      
       }
      


      When I deploy this MDB, it reads the first message that's in the queue and prints out the text.
      The other messages are deleted from the queue but their texts aren't printed out.
      In addition the sender send's a message but nothing happens: no message in the queue and no printing out.

      It seems as the MDB is locking the queue.

        • 1. Re: MDB with Oracle AQ via Sun Adapter
          vickyk

           

          "ryandavid" wrote:

          The other messages are deleted from the queue but their texts aren't printed out.

          Strange!!! You should talk to people in ejb forums about it.

          • 2. Re: MDB with Oracle AQ via Sun Adapter
            kr8670

            Hi,
            I had exactly the same problem some time ago, as in first message got read and the next ones seemed to lock the queue somehow. As I was in a hurry and desperately needed it to work, I did the following:

            1. checked out oracleaq source from cvs.dev.java.net:/cvs
            2. In file com.sun.genericra.inbound.DeliveryHelper at the bottom there should be a line

            ((javax.jms.MessageListener) endPoint).onMessage(message);

            Just after that line I put
            endPoint.afterDelivery();

            And messages started to be delivered as expected.

            3. There was still a problem with JBoss hanging at shutdown, so in com.sun.genericra.inbound.InboundJmsResourcePool waitForAll I replaced
            wait(this.consumer.getSpec().getEndpointReleaseTimeout() * 1000);

            with
            wait(1500);


            There is still an exception thrown at the end of shutdown, but I can live with that for the time beeing. There surely has to be better ways to make this work, but as I said, I was in a hurry...

            • 3. Re: MDB with Oracle AQ via Sun Adapter
              ryandavid

              I tried to put

              endPoint.afterDelivery();

              as you suggested but in this case I don't read any message on the log file. Before this patch the first message was written.

              Can you tell me the version of your oracleaq.rar please ?

              • 4. Re: MDB with Oracle AQ via Sun Adapter
                kr8670

                Hi,
                Well, the version of oracleaq.rar is as checked out from cvs, cvs log shows:

                revision 1.1.1.1
                date: 2007/02/22 10:40:10; author: sauvage; state: Exp; lines: +0 -0
                Oracle AQ JMS Resource Adapter based on Generic JMS RA 1.7
                


                The ra.xml inside tells me:
                <resourceadapter-version>1.8</resourceadapter-version>


                If you are referring to which version of aqapi.jar, I picked the one that came with 10.2.0.3.0. The one with file size 1234676 bytes also gave me possibility to use OCI instead of thin driver. I put he aqapi.jar in server/lib, oracleaq.rar in server/deploy.
                I use jboss-4.2.3.GA, SEAM as developement framework, Suse Linux. This is more or less my setup:
                @MessageDriven(name="ChangeListener",activationConfig={
                 @ActivationConfigProperty(propertyName="DestinationType", propertyValue="javax.jms.Queue")
                })
                
                @ResourceAdapter("oracleaq.rar")
                @Name("changeListener")
                @TransactionManagement(TransactionManagementType.BEAN)
                @Depends("jboss.j2ee:service=EARDeployment,url='crm.ear'")
                public class ChangeListener implements MessageListener {
                
                 @Logger
                 private Log log;
                
                 @Resource
                 private SessionContext sessionContext;
                
                 public void onMessage(Message msg) {
                 final UserTransaction transaction = sessionContext.getUserTransaction();
                
                 try {
                 transaction.begin();
                 if (msg instanceof TextMessage) {
                 ...stuff
                 } else {
                 log.error("Unknown");
                 }
                 transaction.commit();
                 } catch (Exception e) {
                 try {
                 transaction.rollback();
                 } catch (IllegalStateException e1) {
                 e1.printStackTrace();
                 } catch (SecurityException e1) {
                 e1.printStackTrace();
                 } catch (SystemException e1) {
                 e1.printStackTrace();
                 }
                 e.printStackTrace();
                 }
                 }
                }
                

                Most of the config goes in ejb-jar.xml to be able to switch config according to environment:
                 <enterprise-beans>
                 <message-driven>
                 <ejb-name>ChangeListener</ejb-name>
                 <ejb-class>bkk.crm.admin.ChangeListener</ejb-class>
                 <transaction-type>Bean</transaction-type>
                 <activation-config>
                 <activation-config-property>
                 <activation-config-property-name>DestinationType</activation-config-property-name>
                 <activation-config-property-value>javax.jms.Queue</activation-config-property-value>
                 </activation-config-property>
                 <activation-config-property>
                 <activation-config-property-name>ConnectionFactoryProperties</activation-config-property-name>
                 <activation-config-property-value>@mdbConnectionFactoryProperties@</activation-config-property-value>
                 </activation-config-property>
                 <activation-config-property>
                 <activation-config-property-name>DestinationProperties</activation-config-property-name>
                 <activation-config-property-value>@mdbDestinationProperties@</activation-config-property-value>
                 </activation-config-property>
                 <activation-config-property>
                 <activation-config-property-name>UserName</activation-config-property-name>
                 <activation-config-property-value>@mdbUserName@</activation-config-property-value>
                 </activation-config-property>
                 <activation-config-property>
                 <activation-config-property-name>Password</activation-config-property-name>
                 <activation-config-property-value>@mdbPassword@</activation-config-property-value>
                 </activation-config-property>
                 </activation-config>
                 </message-driven>
                 </enterprise-beans>
                


                But, as you already have got to the point where the first message is delivered, this is familiar to you. Anyway, I hope it helps.

                Regards


                • 5. Re: MDB with Oracle AQ via Sun Adapter
                  avogt_sundn

                  yes it works fine, even with today jboss 5.1

                  • 6. Re: MDB with Oracle AQ via Sun Adapter
                    vinnetus

                    I couldn't find the source for oracleaq.rar, if one of you could provide the source code and/or updated rar file would be great.

                    • 7. Re: MDB with Oracle AQ via Sun Adapter
                      krzych_pl

                      I've followed your example but I get such exception:

                       

                        Deployment "jboss.j2ee:jar=test01.jar,name=SampleMDB,service=EJB3" is in error due to the following reason(s): javax.resource.ResourceException: MDB is configured to use container managed transaction. But SupportsXA is configured to false in the resource adapter.

                       

                      Should I set the SupportsXA parameter to true? Where can I do that??

                       

                      EDIT:

                      I used container managed transactions - that is the reason it didn't work. Anyway is it possible to use this mode?

                      • 8. Re: MDB with Oracle AQ via Sun Adapter
                        krzych_pl

                        Have you found this file? I mean updated rar file? Can you send it to me please?

                        • 9. Re: MDB with Oracle AQ via Sun Adapter
                          vinnetus

                          I was able to implement this solution and it works in JBoss 5.1.

                          As per my understanding adapter doesn't support XA transaction and atleast I couldn't find any trace to set it.

                          It just that it took so long to come back over here and post but I actually did blog on this topic, check it out

                          http://vinayshivaswamy.blogspot.com/2012/02/mdb-listening-to-oracle-aq-using-sun.html