繁体   English   中英

如何在WildFly 10.1.0中为Websphere MQ创建JMS侦听器?

[英]How to create a JMS listener for websphere MQ in WildFly 10.1.0?

我有一个可用作在WildFly 10.1.0中运行的jms侦听器的应用程序。 我已经按照该red hat参考配置了资源适配器。

该应用程序的部署没有错误,一切看起来都不错,但是侦听器没有从队列中获取任何消息。 有时,有时会从队列中读取一些消息。 相同的代码在tomcat中运行没有任何问题。

这是我的资源适配器:

<subsystem xmlns="urn:jboss:domain:resource-adapters:4.0">
<resource-adapters>
    <resource-adapter id="wmq">
        <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:jboss/jms/jmsConnectionFactory" enabled="true" use-java-context="true" pool-name="jmsConnectionFactory">
                <config-property name="channel">
                    SYSTEM.DEF.SVRCONN
                </config-property>
                <config-property name="hostName">
                    172.16.41.76
                </config-property>
                <config-property name="transportType">
                    CLIENT
                </config-property>
                <config-property name="queueManager">
                    QM.DEV.01
                </config-property>
                <config-property name="port">
                    1415
                </config-property>
                <security>
                    <application/>
                </security>
            </connection-definition>
        </connection-definitions>
        <admin-objects>
            <admin-object class-name="com.ibm.mq.connector.outbound.MQQueueProxy" jndi-name="java:jboss/jms/QUEUE.TEST.IN" pool-name="QUEUE.TEST.IN">
                <config-property name="baseQueueName">
                    QUEUE.TEST.IN
                </config-property>
                <config-property name="baseQueueManagerName">
                    QM.DEV.01
                </config-property>
            </admin-object>
            <admin-object class-name="com.ibm.mq.connector.outbound.MQQueueProxy" jndi-name="java:jboss/jms/QUEUE.TEST.OUT" pool-name="QUEUE.TEST.OUT">
                <config-property name="baseQueueName">
                    QUEUE.TEST.OUT
                </config-property>
                <config-property name="baseQueueManagerName">
                    QM.DEV.01
                </config-property>
            </admin-object>
        </admin-objects>
    </resource-adapter>
</resource-adapters>

这是检索我的连接工厂的方式:

@Bean(name = "jmsConnectionFactory")
public ConnectionFactory connectionFactory() throws NamingException {
    Context ctx = new InitialContext();
    ConnectionFactory jmsConnectionFactory = (ConnectionFactory) ctx.lookup("java:jboss/jms/jmsConnectionFactory");

    LoggerUtils.logDebug(this.getClass(), "Looking up jms connection factory reference: '{}' -> '{}'", getAppConfigJms().getConnectionFactoryName(), jmsConnectionFactory);
    return jmsConnectionFactory;
}

这是检索我的队列的方式:

public Queue queueLookup(String queueName) throws NamingException, JMSException {
    Context ctx = new InitialContext();
    Queue queue = (Queue) ctx.lookup(queueName);

    LoggerUtils.logDebug(this.getClass(), "Looking up jms queue: '{}' -> '{}'", queueName, queue.getQueueName());
    return queue;
}

这是我的侦听器的创建方式:

public DefaultMessageListenerContainer configureListener(ConnectionFactory connectionFactory,
    Queue destinationQueue, MessageListener messageListener) throws JMSException {

    LoggerUtils.logDebug(this.getClass(), "Starting jms listener '{}' for queue: '{}'", messageListener, (destinationQueue != null ? destinationQueue.getQueueName() : null));

    DefaultMessageListenerContainer listenerContainer = new DefaultMessageListenerContainer();
    listenerContainer.setConnectionFactory(connectionFactory);
    listenerContainer.setDestinationName(destinationQueue.getQueueName());
    listenerContainer.setMessageListener(messageListener);
    listenerContainer.setConcurrentConsumers(getAppConfigJms().getConcurrentConsumers().intValue());
    listenerContainer.setMaxConcurrentConsumers(getAppConfigJms().getMaxConcurrentConsumers().intValue());
    return listenerContainer;
}

有人遇到过同样的问题吗? 如何在WildFly的连接工厂中进行测试?

所以,我的问题解决了。 队列管理器和队列名称有问题。 经过检查并修复所有名称后,现在一切进展顺利。

这是我的固定资源适配器:

<subsystem xmlns="urn:jboss:domain:resource-adapters:4.0">
<resource-adapters>
    <resource-adapter id="wmq">
        <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:jboss/jms/jmsConnectionFactory" enabled="true" pool-name="jmsConnectionFactory">
                <config-property name="hostName">
                    172.16.41.76
                </config-property>
                <config-property name="transportType">
                    CLIENT
                </config-property>
                <config-property name="queueManager">
                    QM.DEV.01
                </config-property>
                <config-property name="port">
                    1415
                </config-property>
                <security>
                    <application/>
                </security>
                <validation>
                    <background-validation>false</background-validation>
                </validation>
            </connection-definition>
        </connection-definitions>
        <admin-objects>
            <admin-object class-name="com.ibm.mq.connector.outbound.MQQueueProxy" jndi-name="java:jboss/jms/QUEUE.TEST.IN" enabled="true" use-java-context="false" pool-name="QUEUE.TEST.IN">
                <config-property name="baseQueueName">
                    QUEUE.TEST.IN
                </config-property>
                <config-property name="baseQueueManagerName">
                    QM.DEV.01
                </config-property>
            </admin-object>
            <admin-object class-name="com.ibm.mq.connector.outbound.MQQueueProxy" jndi-name="java:jboss/jms/QUEUE.TEST.OUT" enabled="true" use-java-context="false" pool-name="QUEUE.TEST.OUT">
                <config-property name="baseQueueName">
                    QUEUE.TEST.OUT
                </config-property>
                <config-property name="baseQueueManagerName">
                    QM.DEV.01
                </config-property>
            </admin-object>
        </admin-objects>
    </resource-adapter>
</resource-adapters>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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