简体   繁体   中英

JBoss connection to MQ from standalone.xml

I am trying to connect to Websphere MQ from a JBoss EAP 6.3 instance. I can get the connection working but it requires me to code the hostname into the bean. Something I'd rather not do. I have some config in the standalone.xml but I don't think those settings are being used.

This is what I have in my standalone.xml:

    <subsystem xmlns="urn:jboss:domain:resource-adapters:1.1">
        <resource-adapters>
            <resource-adapter id="wmq.jmsra.rar">
                <archive>
                    wmq.jmsra.rar
                </archive>
                <transaction-support>NoTransaction</transaction-support>
                <connection-definitions>
                    <connection-definition class-name="com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl" jndi-name="java:/jms/wmqCF" enabled="true" use-java-context="true" pool-name="wmqCF">
                        <config-property name="port">
                            1414
                        </config-property>
                        <config-property name="hostName">
                            my.mqserver.net
                        </config-property>
                        <config-property name="channel">
                            SYSTEM.DEF.SVRCONN
                        </config-property>
                        <config-property name="transportType">
                            CLIENT
                        </config-property>
                        <config-property name="queueManager">
                            MY.QUEUE.MANAGER
                        </config-property>
                    </connection-definition>
                </connection-definitions>
            </resource-adapter>
        </resource-adapters>
    </subsystem>

In my bean I have the following annotations:

@MessageDriven( name="WebSphereMQMDB", 
activationConfig =
{
    @ActivationConfigProperty(propertyName = "destinationType",propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "MQ.QUEUE.NAME")
})

public class WebSphereMQMDB implements MessageListener {
}

When I deploy the above code I get error stating it can't connect to the queue manager at localhost(1414). When I add the hostName property to the bean it does work, like so:

@MessageDriven( name="WebSphereMQMDB", 
activationConfig =
{
    @ActivationConfigProperty(propertyName = "hostName",propertyValue = "my.mqserver.net"),
    @ActivationConfigProperty(propertyName = "destinationType",propertyValue = "javax.jms.Queue"),
    @ActivationConfigProperty(propertyName = "destination", propertyValue = "MQ.QUEUE.NAME")
})

public class WebSphereMQMDB implements MessageListener {
}

How can I get my bean to use the configuration from the standalone.xml so I don't have to set the hostName property in each bean?

Your definition on standalone.xml is valid for outgoing connections to websphere MQ (send a message to a Queue). On an application we migrate from HornetQ to WebSphere we add ejb-jar.xml in your META-INF folder with something like this:

<?xml version='1.0' encoding='UTF-8' ?>
<ejb-jar id="ejb-jar_1" xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"
    version="2.1">

    <enterprise-beans>
        <message-driven>
            <ejb-name>WebSphereMQMDB</ejb-name>
            <ejb-class>com.your.package.WebSphereMQMDB </ejb-class>
            <transaction-type>Container</transaction-type>
            <message-destination-type>javax.jms.Queue</message-destination-type>
            <activation-config>
                <activation-config-property>
                    <activation-config-property-name>maxSession</activation-config-property-name>
                    <activation-config-property-value>8</activation-config-property-value>
                </activation-config-property>
                <activation-config-property> 
                     <activation-config-property-name>destination</activation-config-property-name> 
                     <activation-config-property-value>${com.your.package.MQ.destination}</activation-config-property-value> 
                </activation-config-property> 
                <activation-config-property>
                     <activation-config-property-name>hostName</activation-config-property-name>
                     <activation-config-property-value>${com.your.package.MQ.hostname}</activation-config-property-value>
                </activation-config-property>
                <activation-config-property>
                     <activation-config-property-name>port</activation-config-property-name>
                     <activation-config-property-value>${com.your.package.MQ.port}</activation-config-property-value>
                </activation-config-property>
                <activation-config-property>
                     <activation-config-property-name>queueManager</activation-config-property-name>
                     <activation-config-property-value>${com.your.package.MQ.queuemanager}</activation-config-property-value>
                </activation-config-property>
                <activation-config-property>
                     <activation-config-property-name>channel</activation-config-property-name>
                     <activation-config-property-value>${com.your.package.MQ.channel}</activation-config-property-value>
                </activation-config-property>
                <activation-config-property>
                     <activation-config-property-name>transportType</activation-config-property-name>
                     <activation-config-property-value>${com.your.package.MQ.transporttype}</activation-config-property-value>
                </activation-config-property>
          </activation-config>
        </message-driven>
    </enterprise-beans>
</ejb-jar>

Then you should define the properties on your standalone.xml right after extensions , like:

<system-properties>
    <property name="com.your.package.MQ.destination" value="Q00.APP.AG000001" />
    <property name="com.your.package.MQ.hostname" value="mqserver.yourcompany.com" />
    <property name="com.your.package.MQ.port" value="1416" />
    <property name="com.your.package.MQ.queuemanager" value="Q00" />
    <property name="com.your.package.MQ.channel" value="Q00.APP.SVRCONN" />
    <property name="com.your.package.MQ.transporttype" value="Client" />
</system-properties>

Hope it helps

Note as well that for JBoss EAP 6.3 you can have annotations defined as system properties. In standalone.xml:

    <subsystem xmlns="urn:jboss:domain:ee:1.2">
        <spec-descriptor-property-replacement>true</spec-descriptor-property-replacement>
        <jboss-descriptor-property-replacement>true</jboss-descriptor-property-replacement>
        <annotation-property-replacement>false</annotation-property-replacement>
    </subsystem>

Set annotation-property-replacement to 'true' and you can use ${prop.name} in your MDB source code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM