6 Replies Latest reply on May 26, 2003 7:29 AM by Adrian Brock

    creating only one Message Driven Bean at one time

    johannes rainer Newbie

      hi,
      i have some EJB which have to calculate heavily. i want that at one time only one bean is calculating and the other ones have to wait until the calculating one has finished. is it possible to realize this with message driven beans? so that only one mdb will be created and the others stay in the queue until the other has finished.

      thanks, jo

        • 1. Re: creating only one Message Driven Bean at one time
          rf360 Newbie

          yes it is.

          You can set this up in the jboss.xml file. Add the following tag to your message driven bean configuration:
          <configuration-name>Standard Message Driven Bean</configuration-name>

          Then you'll add a custom configuration that extends this one. Your custom one will specify that only one MDB can be created.

          The full jboss.xml file follows:


          <enterprise-beans>
          <message-driven>
          <ejb-name>myMDB</ejb-name>
          <configuration-name>Standard Message Driven Bean</configuration-name>
          <destination-jndi-name>queue/myQueue</destination-jndi-name>
          <mdb-user>userName</mdb-user>
          <mdb-passwd>password</mdb-passwd>
          </message-driven>
          </enterprise-beans>

          <container-configurations>
          <container-configuration extends="Standard Message Driven Bean">
          <container-name>Standard Message Driven Bean</container-name>
          <container-pool-conf>
          1
          true
          </container-pool-conf>
          </container-configuration>
          </container-configurations>

          • 2. Re: creating only one Message Driven Bean at one time
            Amaresh Kumar Ram Newbie

            Hi,

            I tried the same, but got the following Exception at deployment Time. Find below my Jboss.xml & the Exception log.

            JBOSS.XML:

            <?xml version='1.0' encoding='UTF-8' ?>

            <enterprise-beans>
            <message-driven>
            <ejb-name>EventRouterMDBean</ejb-name>
            <configuration-name>Standard Message Driven Bean</configuration-name>
            <destination-jndi-name>
            queue/SleeQueue
            </destination-jndi-name>
            </message-driven>
            </enterprise-beans>

            <container-configurations>
            <container-configuration extends="Standard Message Driven Bean">
            <container-pool-conf>
            1
            true
            </container-pool-conf>
            </container-configuration>
            </container-configurations>



            And The Exception is:


            org.jboss.deployment.DeploymentException: expected one container-name tag
            at org.jboss.metadata.MetaData.getUniqueChild(MetaData.java:101)
            at org.jboss.metadata.ApplicationMetaData.importJbossXml(ApplicationMetaData.java:492)
            at org.jboss.metadata.XmlFileLoader.load(XmlFileLoader.java:184)
            at org.jboss.ejb.EJBDeployer.create(EJBDeployer.java:321)
            at org.jboss.deployment.MainDeployer.create(MainDeployer.java:760)
            at org.jboss.deployment.MainDeployer.create(MainDeployer.java:752)
            at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:620)
            at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:585)
            at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
            at java.lang.reflect.Method.invoke(Method.java:324)
            at org.jboss.mx.capability.ReflectedMBeanDispatcher.invoke(ReflectedMBeanDispatcher.java:284)
            at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:517)
            at org.jboss.util.jmx.MBeanProxy.invoke(MBeanProxy.java:174)
            at $Proxy4.deploy(Unknown Source)
            at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:435)
            at org.jboss.deployment.scanner.URLDeploymentScanner.scanDirectory(URLDeploymentScanner.java:656)
            at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:507)
            at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:212)
            at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:225)
            at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:202)


            Can someone resolve the Exception.

            regards,
            Amaresh

            • 3. Re: creating only one Message Driven Bean at one time
              Amaresh Kumar Ram Newbie

              Hi,

              Resolved the problem. And it works.

              regards,
              Amaresh

              • 4. Re: creating only one Message Driven Bean at one time
                johannes rainer Newbie

                this has not worked for me. i sent 30 messages to the queue and there where more than 1 MDB performing the calculation at the same time...

                • 5. Re: creating only one Message Driven Bean at one time
                  Elias Ross Master


                  You can do something cheesy like this to limit to one MDB calculating:

                  public class MDB {

                  static Object lock = new Object();

                  public void onMessage(...) {
                  synchronized (lock) {
                  }
                  }

                  }

                  • 6. Re: creating only one Message Driven Bean at one time
                    Adrian Brock Master

                    You want to configure the invoker
                    not the pool.

                    <container-configurations>
                    <container-configuration extends="Standard Message Driven Bean">
                    <container-name>My Message Driven Bean</container-name>
                    <container-invoker-conf>
                    DefaultJMSProvider
                    StdJMSPool
                    1
                    1

                    10

                    queue/DLQ
                    10
                    0


                    </container-invoker-conf>
                    </container-configurations>

                    The strict maximum size didn't work until recent
                    versions of jboss.

                    Regards,
                    Adrian