JBoss 从 standalone.xml 连接到 MQ
JBoss connection to MQ from standalone.xml
我正在尝试从 JBoss EAP 6.3 实例连接到 Websphere MQ。我可以使连接正常工作,但它需要我将主机名编码到 bean 中。我宁愿不做的事情。我在 standalone.xml 中有一些配置,但我认为这些设置没有被使用。
这是我的 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>
在我的 bean 中,我有以下注释:
@MessageDriven( name="WebSphereMQMDB",
activationConfig =
{
@ActivationConfigProperty(propertyName = "destinationType",propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "MQ.QUEUE.NAME")
})
public class WebSphereMQMDB implements MessageListener {
}
当我部署上述代码时,我收到错误消息,指出它无法连接到本地主机 (1414) 的队列管理器。当我将主机名 属性 添加到 bean 时,它确实有效,如下所示:
@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 {
}
如何让我的 bean 使用 standalone.xml 中的配置,这样我就不必在每个 bean 中设置主机名 属性?
您在 standalone.xml 上的定义对于到 websphere MQ 的传出连接有效(向队列发送消息)。在我们从 HornetQ 迁移到 WebSphere 的应用程序中,我们将 ejb-jar.xml 添加到您的 META-INF 文件夹中,其中包含如下内容:
<?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>
然后您应该在 扩展 之后立即定义 standalone.xml 上的属性,例如:
<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>
希望对您有所帮助
另请注意,对于 JBoss EAP 6.3,您可以将注释定义为系统属性。在 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>
将注释-属性-替换设置为'true',您可以在 MDB 源代码中使用 ${prop.name}。
我正在尝试从 JBoss EAP 6.3 实例连接到 Websphere MQ。我可以使连接正常工作,但它需要我将主机名编码到 bean 中。我宁愿不做的事情。我在 standalone.xml 中有一些配置,但我认为这些设置没有被使用。
这是我的 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>
在我的 bean 中,我有以下注释:
@MessageDriven( name="WebSphereMQMDB",
activationConfig =
{
@ActivationConfigProperty(propertyName = "destinationType",propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "MQ.QUEUE.NAME")
})
public class WebSphereMQMDB implements MessageListener {
}
当我部署上述代码时,我收到错误消息,指出它无法连接到本地主机 (1414) 的队列管理器。当我将主机名 属性 添加到 bean 时,它确实有效,如下所示:
@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 {
}
如何让我的 bean 使用 standalone.xml 中的配置,这样我就不必在每个 bean 中设置主机名 属性?
您在 standalone.xml 上的定义对于到 websphere MQ 的传出连接有效(向队列发送消息)。在我们从 HornetQ 迁移到 WebSphere 的应用程序中,我们将 ejb-jar.xml 添加到您的 META-INF 文件夹中,其中包含如下内容:
<?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>
然后您应该在 扩展 之后立即定义 standalone.xml 上的属性,例如:
<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>
希望对您有所帮助
另请注意,对于 JBoss EAP 6.3,您可以将注释定义为系统属性。在 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>
将注释-属性-替换设置为'true',您可以在 MDB 源代码中使用 ${prop.name}。