11 Replies Latest reply on Jun 7, 2013 10:07 AM by bharadwaja.dasari

    JBoss 7.1.1 MDB with IBM MQ - MessageDriven Annotation not configurable

    bharadwaja.dasari Newbie

      I have implemented MDB with Jboss 7.1.1 using IBM MQ Listener. My Listener Code is below

       

      @MessageDriven(

                          activationConfig = {

                                  @ActivationConfigProperty(propertyName = "hostName", propertyValue = "111.11.11.11"),

                                  @ActivationConfigProperty(propertyName = "port", propertyValue = "1420"),

                                  @ActivationConfigProperty(propertyName = "channel", propertyValue = "Channel Name"),

                                  @ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "false"),

                                  @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),

                                  @ActivationConfigProperty(propertyName = "destination", propertyValue = "Name of Destination Queue"),

                                  @ActivationConfigProperty(propertyName = "queueManager", propertyValue = "Queue Manager Name"),

                                  @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),

                                  @ActivationConfigProperty(propertyName = "maxSession", propertyValue = "50")

                          })

      @ResourceAdapter(value="wmq.jmsra.rar")

       

      All this works perfectly(only change here is I have masked the actuals and replaced it with dummies in property values) but the problem is this is all hardcoded. I want it to be configurable, like say if I am in one environment, I want to pick it from properties files for that particular environment

       

      OR  if I use the command to start ./standalone -c standalone-full-xyz.xml, and this standalone-full-xyz.xml should have all the config properties for that environment, so atleast that will help make it configurable

       

      How can I acheive this? Any help.

        • 1. Re: JBoss 7.1.1 MDB with IBM MQ - MessageDriven Annotation not configurable
          Stephen Coy Master

          Move this configuration into jboss-ejb3.xml, whose parser will evaluate EL expressions:

          {code:xml}...

          <message-driven>

               <ejb-name>...</ejb-name>

               <activation-config>

                    <activation-config-property>

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

                         <activation-config-property-value>${mq.host}</activation-config-property-value>

                    </activation-config-property>

                    <activation-config-property>

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

                         <activation-config-property-value>${mq.port}</activation-config-property-value>

                    </activation-config-property>

                    <!-- etc -->

               </activation-config>

          </message-driven>

          ...{code}

           

          and then set the expression values as system properties in your configuration (standalone.xml, etc):

           

          {code:bash}$ ./bin/jboss-cli.sh --connect

          [standalone@localhost:9999 /] /system-property=mq.host:add(value=111.11.11.11)

          [standalone@localhost:9999 /] /system-property=mq.port:add(value=1111)

          [standalone@localhost:9999 /] ...etc

          {code}

          • 2. Re: JBoss 7.1.1 MDB with IBM MQ - MessageDriven Annotation not configurable
            Andrej Golovnin Newbie

            Hi,

            that's easy. You must use deployment descriptors instead of annotations to configure you message driven bean. Your ejb-jar.xml should look like this:

            <?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_0.xsd"
                      version="3.0"
            >
                <enterprise-beans>
                    <message-driven>
                        <ejb-name>MyMDB</ejb-name>
                        <ejb-class>
                            com.foo.MyMDB
                        </ejb-class>
                        <messaging-type>javax.jms.MessageListener</messaging-type>
                        <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>
                                    ${jms.queue.mymdb}
                                </activation-config-property-value>
                            </activation-config-property>
                            <activation-config-property>
                                <activation-config-property-name>
                                    useJNDI
                                </activation-config-property-name>
                                <activation-config-property-value>
                                    false
                                </activation-config-property-value>
                            </activation-config-property>                
                            <activation-config-property>
                                <activation-config-property-name>
                                    channel
                                </activation-config-property-name>
                                <activation-config-property-value>
                                    ${jms.queue.manager.channel}
                                </activation-config-property-value>
                            </activation-config-property>                
                            <activation-config-property>
                                <activation-config-property-name>
                                    hostName
                                </activation-config-property-name>
                                <activation-config-property-value>
                                    ${jms.queue.manager.host}
                                </activation-config-property-value>
                            </activation-config-property>                
                            <activation-config-property>
                                <activation-config-property-name>
                                    queueManager
                                </activation-config-property-name>
                                <activation-config-property-value>
                                    ${jms.queue.manager.name}
                                </activation-config-property-value>
                            </activation-config-property>                
                            <activation-config-property>
                                <activation-config-property-name>
                                    port
                                </activation-config-property-name>
                                <activation-config-property-value>
                                    ${jms.queue.manager.port}
                                </activation-config-property-value>
                            </activation-config-property>                
                            <activation-config-property>
                                <activation-config-property-name>
                                    transportType
                                </activation-config-property-name>
                                <activation-config-property-value>
                                    CLIENT
                                </activation-config-property-value>
                            </activation-config-property>                
                        </activation-config>
                    </message-driven>
                </enterprise-beans>
            </ejb-jar>
            

             

            Notice the values with ${...}? Those are the system properties which you should define in the standalone.xml.

             

            Create also jboss-ejb3.xml descriptor to connect you MDB to the resource adapter:

            <?xml version="1.0" encoding="UTF-8"?>
            <jboss:ejb-jar xmlns:jboss="http://www.jboss.com/xml/ns/javaee"
                           xmlns="http://java.sun.com/xml/ns/javaee"
                           xmlns:mdb="urn:resource-adapter-binding"
                           xmlns:sec="urn:security"
                           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                           xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-ejb3-2_0.xsd http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
                           version="3.1"
                           impl-version="2.0"
            >
                <assembly-descriptor>
                    <mdb:resource-adapter-binding>
                        <ejb-name>MyMDB</ejb-name>
                        <mdb:resource-adapter-name>wmq.jmsra.rar</mdb:resource-adapter-name>
                    </mdb:resource-adapter-binding>
                </assembly-descriptor>
            </jboss:ejb-jar>
            

             

            And now in the standalone.xml define the system properties and activate properties replacement in the descriptors. Here is a snippet from standalone.xml:

            ......
                <system-properties>
                    <!-- JMS properties for ejb-jar.xml -->
                    <property name="jms.queue.manager.channel"  value="QUEUE_MANAGER_CHANNEL"/>
                    <property name="jms.queue.manager.host"     value="QUEUE_MANAGER_HOST"/>
                    <property name="jms.queue.manager.name"     value="QUEUE_MANAGER_NAME"/>
                    <property name="jms.queue.manager.port"     value="QUEUE_MANAGER_PORT"/>
                    <property name="jms.queue.mymdb"            value="MYMDB_QUEUE"/>
                </system-properties>
            ......
                    <subsystem xmlns="urn:jboss:domain:ee:1.1">
                    <spec-descriptor-property-replacement>true</spec-descriptor-property-replacement>
                    <jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement>
                </subsystem>
            ......
            

             

            Hope this helps.

             

            Best regards,

            Andrej Golovnin

            • 3. Re: JBoss 7.1.1 MDB with IBM MQ - MessageDriven Annotation not configurable
              bharadwaja.dasari Newbie

              This might sound like a dumb question but ..do we have to create new ejb-jar.xml and jboss-ejb3.xml? Where should these two files reside like jboss-as-final/standalone/configuration folder? And in my Listener code I should also get rid of the @MessageDriven Annotation and just use @ResourceAdapter?

              • 4. Re: JBoss 7.1.1 MDB with IBM MQ - MessageDriven Annotation not configurable
                Andrej Golovnin Newbie

                You can leave the @MessageDriven annotatioin on your message driven bean but drop all other annotations. The ejb-jar.xml and jboss-ejb3.xml must be palced in the META-INF folder of the JAR-file which contains the message driven bean.

                • 5. Re: JBoss 7.1.1 MDB with IBM MQ - MessageDriven Annotation not configurable
                  bharadwaja.dasari Newbie

                  Andre,

                  Thank you so much for the quick response. I have tried the steps that you have mentioned but I get the below error when starting jboss

                   

                  09:53:32,978 ERROR [org.jboss.as.server] JBAS015956: Caught exception during boot: org.jboss.as.controller.persistence.ConfigurationPersistenceException: JBAS014676: Failed to parse configuration

                         at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:141) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]

                         at org.jboss.as.server.ServerService.boot(ServerService.java:266) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

                         at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:155) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]

                         at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_13]

                  Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[127,3]

                  Message: Unexpected element '{urn:jboss:domain:ee:1.1}subsystem'

                         at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:108) [staxmapper-1.1.0.Final.jar:1.1.0.Final]

                         at org.jboss.staxmapper.XMLExtendedStreamReaderImpl.handleAny(XMLExtendedStreamReaderImpl.java:69) [staxmapper-1.1.0.Final.jar:1.1.0.Final]

                         at org.jboss.as.server.parsing.StandaloneXml.parseServerProfile(StandaloneXml.java:894) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

                         at org.jboss.as.server.parsing.StandaloneXml.readServerElement_1_1(StandaloneXml.java:330) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

                         at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:127) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

                         at org.jboss.as.server.parsing.StandaloneXml.readElement(StandaloneXml.java:100) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

                         at org.jboss.staxmapper.XMLMapperImpl.processNested(XMLMapperImpl.java:110) [staxmapper-1.1.0.Final.jar:1.1.0.Final]

                         at org.jboss.staxmapper.XMLMapperImpl.parseDocument(XMLMapperImpl.java:69) [staxmapper-1.1.0.Final.jar:1.1.0.Final]

                         at org.jboss.as.controller.persistence.XmlConfigurationPersister.load(XmlConfigurationPersister.java:133) [jboss-as-controller-7.1.1.Final.jar:7.1.1.Final]

                         ... 3 more

                   

                  Can you please help?

                  • 6. Re: JBoss 7.1.1 MDB with IBM MQ - MessageDriven Annotation not configurable
                    Stephen Coy Master

                    Please attach ypur deployment descriptors.

                     

                    I'm not sure that ${blah} expressions are supported in the JEE standard descriptors (they haven't in the past, and it's not spec compliant), which is why I suggested using the jboss-ejb3.xml which provides this capability.

                    • 7. Re: JBoss 7.1.1 MDB with IBM MQ - MessageDriven Annotation not configurable
                      bharadwaja.dasari Newbie

                      Hello Stephen,

                       

                      Thank you for the response. I actually tried what you have said earlier and that did not work.

                      • 8. Re: JBoss 7.1.1 MDB with IBM MQ - MessageDriven Annotation not configurable
                        Andrej Golovnin Newbie

                        I'm sorry. I forgot to mention that you need at least JBoss 7.1.3 to get it working.

                         

                        @Stephen: It works. We use it in production for months now. You must just activate property replacement.

                        1 of 1 people found this helpful
                        • 9. Re: JBoss 7.1.1 MDB with IBM MQ - MessageDriven Annotation not configurable
                          bharadwaja.dasari Newbie

                          I have downloaded 7.1.3 and will try it but we are not building it as JAR but building it as a WAR? Will this impact the location of the .xml files?

                          • 10. Re: JBoss 7.1.1 MDB with IBM MQ - MessageDriven Annotation not configurable
                            Andrej Golovnin Newbie

                            Yes, as per specification (EJB 3.1 Spec, Ch. 20.4) you must put the xml-files into WEB-INF folder of the WAR-file.

                            1 of 1 people found this helpful