10 Replies Latest reply on Jun 6, 2012 3:15 PM by Laura delli Paoli

    object message selectors

    Laura delli Paoli Master

      Hello everybody,

      I’d like to now if it is possible to implement a queue with only one MDB class but with a different selector for each instance of it.

       

      Can anyone help me?

      Laura

        • 1. Re: object message selectors
          Justin Bertram Master

          Yes, you can create just one MDB class and use different selectors, but you will need to move all the activation configuration properties to ejb-jar.xml and for each different selector you want you'll have to deploy the MDB in a different jar with the proper ejb-jar.xml.

          1 of 1 people found this helpful
          • 2. Re: object message selectors
            Laura delli Paoli Master

            Thank you Justin,

            So if I have a class MDB and two istances A and B I can let A collect ONLY messages with property color='red' and B only messages with property color='blue'. How can I write such a configuration in my ejb-jar.xml?

            Thanks

            Laura

            • 3. Re: object message selectors
              Justin Bertram Master

              You would deploy your MDB twice.  Each deployment would, of course, have the same MDB class, but each would have a different selector in its ejb-jar.xml. 

              • 4. Re: object message selectors
                Laura delli Paoli Master

                If I do something like this it doesn't work:

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

                <ejb-jar

                          xmlns="http://java.sun.com/xml/ns/javaee"

                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"

                          version="3.1">

                 

                 

                          <description>

                              EJBs for ... application.

                          </description>

                          <enterprise-beans>

                                    <message-driven>

                                              <ejb-name>QueueReader</ejb-name>

                                              <ejb-class>reader.QueueReader</ejb-class>

                                              <transaction-type>Container</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>destination</activation-config-property-name>

                                                                  <activation-config-property-value>queue/TestQ</activation-config-property-value>

                                                        </activation-config-property>

                                                        <activation-config-property>

                                                                  <activation-config-property-name>maxSession</activation-config-property-name>

                                                                  <activation-config-property-value>1</activation-config-property-value>

                                                        </activation-config-property>

                                                        <activation-config-property>

                                                                  <activation-config-property-name>messageSelector</activation-config-property-name>

                                                                  <activation-config-property-value>color = 'RED'</activation-config-property-value>

                                                        </activation-config-property>

                                              </activation-config>

                                    </message-driven>

                                    <message-driven>

                                              <ejb-name>QueueReader</ejb-name>

                                              <ejb-class>reader.QueueReader</ejb-class>

                                              <transaction-type>Container</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>destination</activation-config-property-name>

                                                                  <activation-config-property-value>queue/TestQ</activation-config-property-value>

                                                        </activation-config-property>

                                                        <activation-config-property>

                                                                  <activation-config-property-name>maxSession</activation-config-property-name>

                                                                  <activation-config-property-value>2</activation-config-property-value>

                                                        </activation-config-property>

                                                        <activation-config-property>

                                                                  <activation-config-property-name>messageSelector</activation-config-property-name>

                                                                  <activation-config-property-value>color = 'BLUE'</activation-config-property-value>

                                                        </activation-config-property>

                                              </activation-config>

                                    </message-driven>

                          </enterprise-beans>

                 

                 

                </ejb-jar>

                • 5. Re: object message selectors
                  Justin Bertram Master

                  Just saying, "it doesn't work," isn't terribly helpful.  Were any errors thrown?  Did one MDB receive a message and the other one didn't?  Please elaborate.

                   

                  My guess is that the container is choking on the ejb-jar.xml because you have defined two <message-driven> with the same <ejb-name>.

                   

                  All that said, you're on the right track.

                  • 6. Re: object message selectors
                    Laura delli Paoli Master

                    Only red messages are processed and eclipse ide warns: "cvc-identity-constraint.4.2.2: Duplicate key value [QueueReader] declared for identity constraint "ejb-name-key" of element "ejb-jar"."

                    • 7. Re: object message selectors
                      jaikiran pai Master

                      Laura delli Paoli wrote:

                       

                      eclipse ide warns: "cvc-identity-constraint.4.2.2: Duplicate key value [QueueReader] declared for identity constraint "ejb-name-key" of element "ejb-jar"."

                      Justin already pointed out what's wrong with that ejb-jar.xml file:

                      Justin Bertram wrote:

                       

                      My guess is that the container is choking on the ejb-jar.xml because you have defined two <message-driven> with the same <ejb-name>.

                      • 8. Re: object message selectors
                        Laura delli Paoli Master

                        If I give the ebj QueueReaderBlue and QueueReaderRed respectively I cannot see the application deployed.

                         

                         

                        17:17:42,172 INFO  [org.jboss.modules] JBoss Modules version 1.1.1.GA

                        17:17:42,435 INFO  [org.jboss.msc] JBoss MSC version 1.0.2.GA

                        17:17:42,515 INFO  [org.jboss.as] JBAS015899: JBoss AS 7.1.1.Final "Brontes" starting

                        17:17:44,837 INFO  [org.jboss.as.server] JBAS015888: Creating http management service using socket-binding (management-http)

                        17:17:44,837 INFO  [org.xnio] XNIO Version 3.0.3.GA

                        17:17:44,853 INFO  [org.xnio.nio] XNIO NIO Implementation Version 3.0.3.GA

                        17:17:44,870 INFO  [org.jboss.remoting] JBoss Remoting version 3.2.3.GA

                        17:17:44,901 INFO  [org.jboss.as.logging] JBAS011502: Removing bootstrap log handlers

                        17:17:44,911 INFO  [org.jboss.as.configadmin] (ServerService Thread Pool -- 32) JBAS016200: Activating ConfigAdmin Subsystem

                        17:17:44,928 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 37) JBAS010280: Activating Infinispan subsystem.

                        17:17:44,929 INFO  [org.jboss.as.security] (ServerService Thread Pool -- 54) JBAS013101: Activating Security Subsystem

                        17:17:44,955 INFO  [org.jboss.as.webservices] (ServerService Thread Pool -- 58) JBAS015537: Activating WebServices Extension

                        17:17:44,975 INFO  [org.jboss.as.osgi] (ServerService Thread Pool -- 49) JBAS011940: Activating OSGi Subsystem

                        17:17:44,975 INFO  [org.jboss.as.jacorb] (ServerService Thread Pool -- 38) JBAS016300: Activating JacORB Subsystem

                        17:17:44,982 INFO  [org.jboss.as.naming] (ServerService Thread Pool -- 48) JBAS011800: Activating Naming Subsystem

                        17:17:45,000 INFO  [org.jboss.as.security] (MSC service thread 1-3) JBAS013100: Current PicketBox version=4.0.7.Final

                        17:17:45,170 INFO  [org.jboss.as.connector] (MSC service thread 1-2) JBAS010408: Starting JCA Subsystem (JBoss IronJacamar 1.0.9.Final)

                        17:17:45,180 INFO  [org.jboss.as.naming] (MSC service thread 1-2) JBAS011802: Starting Naming Service

                        17:17:45,232 INFO  [org.jboss.as.mail.extension] (MSC service thread 1-8) JBAS015400: Bound mail session [java:jboss/mail/Default]

                        17:17:45,235 INFO  [org.jboss.jaxr] (MSC service thread 1-2) JBAS014000: Started JAXR subsystem, binding JAXR connection factory into JNDI as: java:jboss/jaxr/ConnectionFactory

                        17:17:45,236 INFO  [org.jboss.ws.common.management.AbstractServerConfig] (MSC service thread 1-1) JBoss Web Services - Stack CXF Server 4.0.2.GA

                        17:17:45,310 INFO  [org.jboss.as.connector.subsystems.datasources] (ServerService Thread Pool -- 33) JBAS010403: Deploying JDBC-compliant driver class org.h2.Driver (version 1.3)

                        17:17:46,003 INFO  [org.apache.coyote.http11.Http11Protocol] (MSC service thread 1-1) Starting Coyote HTTP/1.1 on http-localhost-127.0.0.1-8080

                        17:17:46,092 INFO  [org.jboss.as.server.deployment.scanner] (MSC service thread 1-3) JBAS015012: Started FileSystemDeploymentService for directory C:\eseguibili\jboss-as-7.1.1\standalone\deployments

                        17:17:46,101 INFO  [org.jboss.as.remoting] (MSC service thread 1-8) JBAS017100: Listening on localhost/127.0.0.1:4447

                        17:17:46,126 WARN  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015002: Deployment of 'TopicReader-EAR' requested, but the deployment is not present

                        17:17:46,129 WARN  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015002: Deployment of 'QueueReader' requested, but the deployment is not present

                        17:17:46,130 INFO  [org.jboss.as.remoting] (MSC service thread 1-7) JBAS017100: Listening on /127.0.0.1:9999

                        17:17:46,131 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found HelloWorld-mdb.jar in deployment directory. To trigger deployment create a file called HelloWorld-mdb.jar.dodeploy

                        17:17:46,138 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found jboss-as-helloworld.jar in deployment directory. To trigger deployment create a file called jboss-as-helloworld.jar.dodeploy

                        17:17:46,140 INFO  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015003: Found JBossQueueReader.jar in deployment directory. To trigger deployment create a file called JBossQueueReader.jar.dodeploy

                        17:17:46,209 WARN  [org.jboss.as.messaging] (MSC service thread 1-5) JBAS011600: AIO wasn't located on this platform, it will fall back to using pure Java NIO. If your platform is Linux, install LibAIO to enable the AIO journal

                        17:17:46,257 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) JBAS010400: Bound data source [java:jboss/datasources/ExampleDS]

                        17:17:46,282 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-5) live server is starting with configuration HornetQ Configuration (clustered=false,backup=false,sharedStore=true,journalDirectory=C:\eseguibili\jboss-as-7.1.1\standalone\data\messagingjournal,bindingsDirectory=C:\eseguibili\jboss-as-7.1.1\standalone\data\messagingbindings,largeMessagesDirectory=C:\eseguibili\jboss-as-7.1.1\standalone\data\messaginglargemessages,pagingDirectory=C:\eseguibili\jboss-as-7.1.1\standalone\data\messagingpaging)

                        17:17:46,290 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-5) Waiting to obtain live lock

                        17:17:46,328 INFO  [org.hornetq.core.persistence.impl.journal.JournalStorageManager] (MSC service thread 1-5) Using NIO Journal

                        17:17:46,345 WARN  [jacorb.codeset] (MSC service thread 1-3) Warning - unknown codeset (Cp1252) - defaulting to ISO-8859-1

                        17:17:46,380 INFO  [org.jboss.as.jacorb] (MSC service thread 1-3) JBAS016330: CORBA ORB Service started

                        17:17:46,520 INFO  [org.hornetq.core.server.impl.FileLockNodeManager] (MSC service thread 1-5) Waiting to obtain live lock

                        17:17:46,522 INFO  [org.hornetq.core.server.impl.FileLockNodeManager] (MSC service thread 1-5) Live Server Obtained live lock

                        17:17:46,621 INFO  [org.jboss.as.jacorb] (MSC service thread 1-1) JBAS016328: CORBA Naming Service started

                        17:17:47,075 INFO  [org.hornetq.core.remoting.impl.netty.NettyAcceptor] (MSC service thread 1-5) Started Netty Acceptor version 3.2.5.Final-a96d88c localhost:5445 for CORE protocol

                        17:17:47,080 INFO  [org.hornetq.core.remoting.impl.netty.NettyAcceptor] (MSC service thread 1-5) Started Netty Acceptor version 3.2.5.Final-a96d88c localhost:5455 for CORE protocol

                        17:17:47,085 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-5) Server is now live

                        17:17:47,087 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-5) HornetQ Server version 2.2.13.Final (HQ_2_2_13_FINAL_AS7, 122) [c038a3ed-a64f-11e1-ba0b-005056c00001]) started

                        17:17:47,091 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-7) trying to deploy queue jms.topic.testTopicLaura

                        17:17:47,130 INFO  [org.jboss.as.messaging] (MSC service thread 1-7) JBAS011601: Bound messaging object to jndi name java:/topic/testT

                        17:17:47,133 INFO  [org.jboss.as.messaging] (MSC service thread 1-7) JBAS011601: Bound messaging object to jndi name java:jboss/exported/jms/topic/testT

                        17:17:47,155 INFO  [org.jboss.as.messaging] (MSC service thread 1-3) JBAS011601: Bound messaging object to jndi name java:/ConnectionFactory

                        17:17:47,157 INFO  [org.jboss.as.messaging] (MSC service thread 1-1) JBAS011601: Bound messaging object to jndi name java:jboss/exported/jms/RemoteConnectionFactory

                        17:17:47,159 INFO  [org.jboss.as.messaging] (MSC service thread 1-1) JBAS011601: Bound messaging object to jndi name java:/RemoteConnectionFactory

                        17:17:47,161 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-4) trying to deploy queue jms.queue.testQ

                        17:17:47,162 INFO  [org.jboss.as.deployment.connector] (MSC service thread 1-5) JBAS010406: Registered connection factory java:/JmsXA

                        17:17:47,173 INFO  [org.jboss.as.messaging] (MSC service thread 1-4) JBAS011601: Bound messaging object to jndi name java:/queue/TestQ

                        17:17:47,175 INFO  [org.jboss.as.messaging] (MSC service thread 1-4) JBAS011601: Bound messaging object to jndi name java:jboss/exported/jms/queue/TestQ

                        17:17:47,178 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-6) trying to deploy queue jms.topic.testTopic

                        17:17:47,176 INFO  [org.hornetq.ra.HornetQResourceAdapter] (MSC service thread 1-5) HornetQ resource adaptor started

                        17:17:47,186 INFO  [org.jboss.as.connector.services.ResourceAdapterActivatorService$ResourceAdapterActivator] (MSC service thread 1-5) IJ020002: Deployed: file://RaActivatorhornetq-ra

                        17:17:47,184 INFO  [org.jboss.as.messaging] (MSC service thread 1-6) JBAS011601: Bound messaging object to jndi name java:/topic/test

                        17:17:47,218 INFO  [org.jboss.as.deployment.connector] (MSC service thread 1-5) JBAS010401: Bound JCA ConnectionFactory [java:/JmsXA]

                        17:17:47,219 INFO  [org.jboss.as.messaging] (MSC service thread 1-6) JBAS011601: Bound messaging object to jndi name java:jboss/exported/jms/topic/test

                        17:17:47,222 INFO  [org.hornetq.core.server.impl.HornetQServerImpl] (MSC service thread 1-8) trying to deploy queue jms.queue.testQueue

                        17:17:47,224 INFO  [org.jboss.as.messaging] (MSC service thread 1-8) JBAS011601: Bound messaging object to jndi name java:/queue/test

                        17:17:47,226 INFO  [org.jboss.as.messaging] (MSC service thread 1-8) JBAS011601: Bound messaging object to jndi name java:jboss/exported/jms/queue/test

                        17:17:47,264 INFO  [org.jboss.as.server.deployment] (MSC service thread 1-4) JBAS015876: Starting deployment of "jboss-as-helloworld.jar"

                        17:17:47,443 INFO  [org.jboss.as] (MSC service thread 1-5) JBAS015951: Admin console listening on http://127.0.0.1:9990

                        17:17:47,444 INFO  [org.jboss.as] (MSC service thread 1-5) JBAS015874: JBoss AS 7.1.1.Final "Brontes" started in 5620ms - Started 197 of 278 services (80 services are passive or on-demand)

                        17:17:47,572 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "jboss-as-helloworld.jar"

                        • 9. Re: object message selectors
                          jaikiran pai Master

                          17:17:46,126 WARN  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015002: Deployment of 'TopicReader-EAR' requested, but the deployment is not present

                          17:17:46,129 WARN  [org.jboss.as.server.deployment.scanner] (DeploymentScanner-threads - 1) JBAS015002: Deployment of 'QueueReader' requested, but the deployment is not present

                          How are you deploying the  application? What is the name of the application?

                          • 10. Re: object message selectors
                            Laura delli Paoli Master

                            I'm deployng using eclipse (debugging on server). The application name is JBossQueueReader. The MDB class name is QueueReader.