9 Replies Latest reply on May 27, 2006 2:50 PM by bitl

    Can't use EJB3 MDB to retrieve messages one by one.

    bitl

      Hello!
      I'll be as short as possible. Thank you.
      Jboss version: 4.0.4RC1
      EJB3 version: rc5-PFD
      JRE: 1.5.0_06
      My persistent queue config:

      <mbean code="org.jboss.mq.server.jmx.Queue"
       name="jboss.mq.destination:service=Queue,name=myQueue1">
       <depends optional-attribute-name="DestinationManager">jboss.mq:service=DestinationManager</depends>
       <attribute name="MessageCounterHistoryDayLimit">-1</attribute>
      </mbean>
      

      My MDB class annotated:
      @MessageDriven(activationConfig = {
      @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
      @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/myQueue1"),
      @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Client-acknowledge")
       })
      public class BlogKsgMDBean implements MessageListener {

      I'm using several threads to post messages to myQueue1 simultaneously.
      Looking over my debug log I see that several instances of my MDB also starts simultaneously.
      I would like to get it work to handle messages one by one.
      No get next message from queue until current handle finish.
      But still using MessageListener instead of .receive() method.
      Is it possible? How do I have to configure it?
      Here's how I post message:
      conn = jmsConnectionFactory.createConnection();
      //sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
      producer = sess.createProducer((Destination) namingContext.lookup("queue/myQueue1"));
      ObjectMessage msg = sess.createObjectMessage(message);
      producer.send(msg);
      producer.close();
      sess.close();
      conn.close();


        • 1. Re: Can't use EJB3 MDB to retrieve messages one by one.
          jaikiran

          MDBs are meant to start messages simultaneously.

          • 2. Re: Can't use EJB3 MDB to retrieve messages one by one.
            jaikiran

             

            start messages simultaneously


            I meant, start processing messages simultaneously.



            • 3. Re: Can't use EJB3 MDB to retrieve messages one by one.

              use the Singleton configuration:

              <message-driven>
               <configuration-name>Singleton Message Driven Bean</configuration-name>
               <ejb-name>XARecovery2ResMDB</ejb-name>
               <destination-jndi-name>queue/@QUEUE_NAME@</destination-jndi-name>
              </message-driven>
              


              • 4. Re: Can't use EJB3 MDB to retrieve messages one by one.
                bitl

                 

                "mskonda" wrote:
                use the Singleton configuration:
                <message-driven>
                 <configuration-name>Singleton Message Driven Bean</configuration-name>
                 <ejb-name>XARecovery2ResMDB</ejb-name>
                 <destination-jndi-name>queue/@QUEUE_NAME@</destination-jndi-name>
                </message-driven>
                


                Thanks to all.

                I explicitly added name to annotation:
                @MessageDriven(name = "MyMDBean",


                Created jboss.xml:
                <jboss>
                 <enterprise-beans>
                 <message-driven>
                 <ejb-name>MyMDBean</ejb-name>
                 <destination-jndi-name>queue/myQueue1</destination-jndi-name>
                 <configuration-name>Singleton Message Driven Bean</configuration-name>
                 </message-driven>
                 </enterprise-beans>
                </jboss>
                


                Got error:
                2006-05-17 15:05:28,448 WARN [org.jboss.system.ServiceController] Problem creating service jboss.j2ee:service=EJB3,module=dvase-mdb.blog.ksg.jar
                org.jboss.xb.binding.JBossXBException: Failed to parse source
                 at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:138)
                ...
                Caused by: java.lang.ClassCastException: org.jboss.ejb3.dd.SessionEnterpriseBean
                 at org.jboss.ejb3.dd.EnterpriseBeans.setDestinationJndiName(EnterpriseBeans.java:98)
                 at org.jboss.ejb3.dd.JBossDDObjectFactory.setValue(JBossDDObjectFactory.java:697)
                ...
                 at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
                 at org.jboss.xb.binding.parser.sax.SaxJBossXBParser.parse(SaxJBossXBParser.java:134)
                


                • 5. Re: Can't use EJB3 MDB to retrieve messages one by one.
                  mannef

                  Did you figure out why you got this message, because I'm getting the exact same problem with an MDB on 4.0.4RC1.

                  Looks like a bug in the SaxJBossXBParser, because this is obviously no session EJB. Is this a known issue?

                  • 6. Re: Can't use EJB3 MDB to retrieve messages one by one.
                    bitl

                     

                    "ManneF" wrote:
                    Did you figure out why you got this message, because I'm getting the exact same problem with an MDB on 4.0.4RC1.

                    Looks like a bug in the SaxJBossXBParser, because this is obviously no session EJB. Is this a known issue?


                    Not yet.
                    Just have no time to dig it.
                    Currently I'm using ugly solution to synchronize onMessage method on static object.
                    Thus I no need to reprogram message reading but have something close to what I need.

                    • 7. Re: Can't use EJB3 MDB to retrieve messages one by one.
                      mannef

                      You may want to consider using a database lock instead.

                      Using statics is inherently risky in a J2EE environment, because your class may be loaded many times by different class loaders.

                      • 8. Re: Can't use EJB3 MDB to retrieve messages one by one.
                        bitl

                         

                        "ManneF" wrote:
                        You may want to consider using a database lock instead.

                        Using statics is inherently risky in a J2EE environment, because your class may be loaded many times by different class loaders.


                        I got my MDBs to be always one per queue reducing their pool sizes:
                        @ActivationConfigProperty(propertyName = "MaxPoolSize", propertyValue = "1"),


                        Is it valid solution?

                        • 9. Re: Can't use EJB3 MDB to retrieve messages one by one.
                          bitl

                           

                          "mskonda" wrote:
                          use the Singleton configuration:
                          <message-driven>
                           <configuration-name>Singleton Message Driven Bean</configuration-name>
                           <ejb-name>XARecovery2ResMDB</ejb-name>
                           <destination-jndi-name>queue/@QUEUE_NAME@</destination-jndi-name>
                          </message-driven>
                          


                          I got my MDBs to be always one per queue reducing their pool sizes:

                          @ActivationConfigProperty(propertyName = "MaxPoolSize", propertyValue = "1"),


                          Is it a valid solution?