2

我想在我的服务器配置中指定队列的位置(队列管理器和队列名称)。

我有一个 MDB,只使用以下内容;

多边开发银行:

@MessageDriven(name = "smis2/DelmeMDB"
, activationConfig = {
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
        @ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/jms/queue/CLQ"),
        @ActivationConfigProperty(propertyName = "useJNDI", propertyValue = "true"),
        @ActivationConfigProperty(propertyName = "transportType", propertyValue = "BINDINGS"),
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")
        }
, mappedName="java:/jms/queue/A"
)
@ResourceAdapter("wmq.jmsra.rar")
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class DelmeMDB implements MessageListener {

    public DelmeMDB() {

    }
    @Override
    public synchronized void onMessage(Message message) {
        String msgStr = null;
        try {
            if (message instanceof BytesMessage) {
                BytesMessage bm = (BytesMessage) message;
                byte[] buf = new byte[(int)bm.getBodyLength()];
                bm.readBytes(buf);
                msgStr = new String(buf, "utf8");
            } else if (message instanceof TextMessage) {
                TextMessage txtMsg = (TextMessage) message;
                msgStr = txtMsg.getText();
            } else {
                throw new EJBException("Unrecognized message type");
            }

            if (msgStr != null) {
                System.out.printf("Got a message! %s%n", msgStr);
            }
        } catch (Exception e) {
            throw new EJBException(e);
        } finally {
        }
    }
}

在我的服务器配置中:

<subsystem xmlns="urn:jboss:domain:resource-adapters:1.0">
            <resource-adapters>
                <resource-adapter>
                    <archive>
                        wmq.jmsra.rar
                    </archive>
                    <transaction-support>XATransaction</transaction-support>
                    <connection-definitions>
                        <connection-definition class-name="com.ibm.mq.connector.outbound.ManagedConnectionFactoryImpl" jndi-name="java:/WMQCF" enabled="true" use-java-context="true" pool-name="WMQCF" use-ccm="true">
                            <config-property name="transportType">
                                ${pnp.mq.transportType:BINDINGS}
                            </config-property>
                            <config-property name="queueManager">
                                ${pnp.mq.queueManager:MB8QMGR}
                            </config-property>
                            <xa-pool>
                                <min-pool-size>1</min-pool-size>
                                <max-pool-size>5</max-pool-size>
                                <prefill>true</prefill>
                                <use-strict-min>true</use-strict-min>
                                <flush-strategy>FailingConnectionOnly</flush-strategy>
                            </xa-pool>
                            <validation>
                                <background-validation>false</background-validation>
                                <use-fast-fail>false</use-fast-fail>
                            </validation>
                        </connection-definition>
                    </connection-definitions>
                    <admin-objects>
                        <admin-object class-name="com.ibm.mq.connector.outbound.MQQueueProxy" jndi-name="java:/jms/queue/CLQ" enabled="true" use-java-context="false" pool-name="java:/jms/queue/CLQ">
                            <config-property name="baseQueueManagerName">
                                ${pnp.mq.queueManager:MB8QMGR}
                            </config-property>
                            <config-property name="baseQueueName">
                                CLQ
                            </config-property>
                        </admin-object>
                    </admin-objects>
                </resource-adapter>
            </resource-adapters>
        </subsystem>

现在,只要我连接的队列管理器是系统上的默认队列管理器,它就可以工作。我尝试切换到不同的本地队列管理器(不是默认的),即使管理对象被适当更新,它也无法工作。无论如何,我宁愿不依赖系统范围的默认值并明确声明队列管理器。

或者,我可以设置 useJNDI=false,并在 jboss-ejb3.xml 中提供它:

    <message-driven>
        <ejb-name>smis2/DelmeMDB</ejb-name>
        <ejb-class>pnp.smis2.ejb.DelmeMDB</ejb-class>
        <activation-config>
            <activation-config-property>
                <activation-config-property-name>transportType</activation-config-property-name>
                <activation-config-property-value>${pnp.mq.transportType}</activation-config-property-value>
            </activation-config-property>
            <activation-config-property>
                <activation-config-property-name>queueManager</activation-config-property-name>
                <activation-config-property-value>${pnp.mq.queueManager}</activation-config-property-value>
            </activation-config-property>
        </activation-config>
    </message-driven>
</enterprise-beans>

这很好用,而且我可以通过使用系统属性替换来指定完整的激活规范选项。但是,如果我需要对 jboss-ejb3.xml 进行结构更改以部署到我的本地、开发、qa 和生产环境,则很难(不可能?)使用此方案。

如何消除 jboss-ejb3.xml,并通过在standalone.xml(或 domain.xml)中混合特定于节点的项目和更通用的选项作为@ActivationConfigProperys 来提供配置?

4

0 回答 0