Ibm mq 春天&;Websphere MQ:应用程序未拾取消息

Ibm mq 春天&;Websphere MQ:应用程序未拾取消息,ibm-mq,spring-jms,Ibm Mq,Spring Jms,我有一个使用SpringJMS、WebSphereMQ、WebSphereApplicationServer7的应用程序。 在用户交互中,我将消息放入队列a中。我有一个侦听器a(在springframework中使用DefaultMessageListenerContainer)来拾取消息。侦听器A应该处理它并向队列A-response发送响应。在这个过程中,我试图将另一条消息放在不同的队列B上,我为该队列定义了不同的侦听器B。但是由于某种原因,在消息被放入队列B之后,侦听器B没有接收到它。 当

我有一个使用SpringJMS、WebSphereMQ、WebSphereApplicationServer7的应用程序。 在用户交互中,我将消息放入队列a中。我有一个侦听器a(在springframework中使用DefaultMessageListenerContainer)来拾取消息。侦听器A应该处理它并向队列A-response发送响应。在这个过程中,我试图将另一条消息放在不同的队列B上,我为该队列定义了不同的侦听器B。但是由于某种原因,在消息被放入队列B之后,侦听器B没有接收到它。 当我尝试手动将消息放入队列B时,Listener-B会选择消息并对其进行处理,但当我尝试上述场景时,它不起作用。另外,当我注释掉将消息放入Listener-a中的队列B的代码时,Listener-a处理该消息并将响应发送回队列a-response

非常感谢您的帮助。谢谢

编辑:添加代码

这是我的spring配置

    <bean id="jmsListener-Parent" abstract="true"
    class="MyJmsServiceExporter">
    <property name="messageTimeToLive" value="60000" />
</bean>

<bean id="transactionManager" class="org.springframework.transaction.jta.WebSphereUowTransactionManager" />

<bean id="taskExecutor" class="org.springframework.scheduling.commonj.WorkManagerTaskExecutor">
    <property name="workManagerName" value="wm/default" />
</bean>

<bean name="jmsListenerContainer-Parent"
      abstract="true"
      class="org.springframework.jms.listener.DefaultMessageListenerContainer">
    <property name="connectionFactory" ref="connectionFactory"/>
    <property name="concurrentConsumers" value="1"/>
    <property name="transactionManager" ref="transactionManager" />  
    <property name="taskExecutor" ref="taskExecutor" />
</bean>

<bean id="FirstService-Listener" parent="jmsListener-Parent">
    <property name="serviceInterface" value="FirstService" />
    <property name="service" ref="FirstServiceImpl" />
    <property name="messageConverter" ref="MyMessageConverter" />
</bean>

<bean id="SecondService-Listener" parent="jmsListener-Parent">
    <property name="serviceInterface" value="SecondService" />
    <property name="service" ref="SecondServiceImpl" />
    <property name="messageConverter" ref="MyMessageConverter" />
</bean>

<bean name="FirstService-ListenerContainer"
      parent="jmsListenerContainer-Parent">
    <property name="destination" ref="FirstQueue-Request" />
    <property name="messageListener" ref="FirstService-Listener" />
</bean>

<bean name="SecondService-ListenerContainer"
      parent="jmsListenerContainer-Parent">
    <property name="destination" ref="SecondQueue-Request" />
    <property name="messageListener" ref="SecondService-Listener" />
</bean>

<bean id="FirstService-Client"
      class="MyJmsServiceInvoker">
    <property name="connectionFactory" ref="connectionFactory" />          
    <property name="serviceInterface" value="FirstService" />
    <property name="messageConverter" ref="MyMessageConverter" />
    <property name="queue" ref="FirstQueue-Request" />
    <property name="responseQueue" ref="FirstQueue-Response" />
    <property name="timeToLive" value="60000" />
    <property name="receiveTimeout" value="60000" />            
</bean>  

<bean id="SecondService-Client"
      class="MyJmsServiceInvoker">
    <property name="connectionFactory" ref="connectionFactory" />          
    <property name="serviceInterface" value="SecondService" />
    <property name="messageConverter" ref="MyMessageConverter" />
    <property name="queue" ref="SecondQueue-Request" />
    <property name="responseQueue" ref="SecondQueue-Response" />
    <property name="timeToLive" value="60000" />
    <property name="receiveTimeout" value="60000" />            
</bean> 
MyJmsServiceExporter(扩展JmsInvokerServiceExporter)方法:


FirstServiceImpl类有一个saveText方法,当消息放入FirstQueue请求时调用该方法。在该方法中,我尝试调用第二个服务方法:validateText(textmessage)。此消息被置于第二个队列请求中,但从未被读取。

在消息发送后,您没有提交会话

在我看来,您试图通过correlationid逻辑实现请求-应答,同时处理事务资源和手动会话处理;都在同一个方法(doExecuteRequest()或writeRemoteInvocationResult()中)。对于20行代码来说,这是很多东西。这种代码通常用于临时队列


您真的需要在会话级别编写代码吗?有什么原因不能只使用jmsTemplate发送消息,而使用messageListenerContainer接收回复

对于这样的问题,您需要提供更多的细节。如果您使用的是事务,则在提交初始事务之前,发送到队列B不会被提交(可用于接收)。如果来自队列A的请求正在等待对发送到队列B的消息的响应,那么它将永远不会发生。如果是这种情况,您需要为队列B交互启动一个新事务。
protected Message doExecuteRequest(
        Session session,
        Queue queue,
        Message requestMessage) 
throws JMSException {
    MessageProducer producer = null;
    MessageConsumer consumer = null;
    Message responseMessage = null;
    String correlationId = null;
    String responseSelector = null;

    try {
        LOG.info("CmsJmsServiceInvoker::doExecuteRequest");
        requestMessage.setJMSType("TEXT");
        requestMessage.setJMSReplyTo(responseQueue);
        requestMessage.setJMSExpiration(this.getTimeToLive());

        producer = session.createProducer(queue);

        if (isPersistentMessage()) {
            producer.setDeliveryMode(DeliveryMode.PERSISTENT);
        } else {
            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        }

        producer.setTimeToLive(getTimeToLive());

        LOG.info("Sending requestMessage.");
        producer.send(requestMessage);

        correlationId = requestMessage.getJMSMessageID();
        responseSelector = 
            "JMSCorrelationID=\'" + correlationId + "\'";

        consumer = session.createConsumer(responseQueue, responseSelector);

        long timeout = getReceiveTimeout();

        LOG.info("Awaiting response.");
        if (timeout > 0) {
            responseMessage = consumer.receive(timeout);
        } else {
            responseMessage = consumer.receive();
        }

        if (responseMessage == null) {
            LOG.info("Timeout encountered.");
            throw new RuntimeException("Timeout");
        }
    } catch (JMSSecurityException jse) {
        LOG.error("SecurityException encountered.", jse);
        throw new RuntimeException("JMS SecurityException, jse");

    } finally {
        JmsUtils.closeMessageConsumer(consumer);
        JmsUtils.closeMessageProducer(producer);
    }

    LOG.info("Returning response Message.");
    return responseMessage;      
}
protected void writeRemoteInvocationResult(Message requestMessage,
                                           Session session,
                                           RemoteInvocationResult result)
throws JMSException {
    MessageProducer producer = null;
    Message response = null;
    if (requestMessage.getJMSReplyTo() == null) {
        LOG.debug("Async:  This request will not have a "
                  + "response since there is no reply queue in the "
                  + "JMS header.");
        return;
    }

    producer = session.createProducer(requestMessage.getJMSReplyTo());

    try {
        response = createResponseMessage(requestMessage, session,
                result);
        producer.setTimeToLive(getMessageTimeToLive());
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

        if (persistentMessage) {
            producer.setDeliveryMode(DeliveryMode.PERSISTENT);
        }
        producer.send(response);

        if (LOG.isDebugEnabled()) {
            LOG.debug("Sending response message.");
            LOG.debug(response);
        }
    } finally {
        if (producer != null) {
            JmsUtils.closeMessageProducer(producer);
        }
    }
}

protected Message createResponseMessage(
        Message request,
        Session session,
        RemoteInvocationResult result) 
throws JMSException {
    Message response = null;
    String correlation = null;

    correlation = request.getJMSCorrelationID();

    response = super.createResponseMessage(request, session, result);
    if (correlation == null) {
        correlation = request.getJMSMessageID();
    }

    response.setJMSCorrelationID(correlation);
    response.setJMSExpiration(getMessageTimeToLive());

    return response;
}  


public void onMessage(Message requestMessage, Session session)
        throws JMSException {
    RemoteInvocationResult result = null;

    try {
        RemoteInvocation invocation = readRemoteInvocation(requestMessage);

        if (invocation != null) {
            result = 
                invokeAndCreateResult(invocation, getProxyForService());
        }
    } catch (Throwable throwable) {
        if (result == null) {
            result = new RemoteInvocationResult(throwable);
        }

        throwable.printStackTrace();
    } finally {
        writeRemoteInvocationResult(requestMessage, session, result);
        // JmsUtils.commitIfNecessary(session);
    }
}