1
在Spring 4應用程序中使用WebSphere MQ,並在偵聽到MQ(發送消息工作正常)時遇到一些麻煩。如何使用Spring 4的JmsTemplate從MQ偵聽消息?
這裏是我的一塊mvc-dispatcher-servlet.xml
文件,我指定我的信息,我的JmsTemplate
:
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="appJmsConnectionFactory" />
<property name="defaultDestinationName" value="MQ.LISTENER.INFO.HERE" />
<property name="sessionTransacted" value="true" />
</bean>
這裏是我的監聽器類:
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Component;
@Component
public class SpringJmsConsumer {
@Autowired
private JmsTemplate jmsTemplate;
private Destination destination;
public JmsTemplate getJmsTemplate() {
return jmsTemplate;
}
public void setJmsTemplate(JmsTemplate jmsTemplate) {
this.jmsTemplate = jmsTemplate;
}
public Destination getDestination() {
return destination;
}
public void setDestination(Destination destination) {
this.destination = destination;
}
public String receiveMessage() throws JMSException {
Message message = jmsTemplate.receive(jmsTemplate.getDefaultDestination());
// TextMessage textMessage = (TextMessage)
// jmsTemplate.receive(destination);
System.out.println("The message listened is: " + message.toString());
return message.toString();
}
}
的錯誤,我得到:
org.springframework.jms.InvalidDestinationException: JMSMQ0003: The destination is not understood or no longer valid.; nested exception is com.ibm.msg.client.jms.DetailedInvalidDestinationException: JMSMQ0003: The destination is not understood or no longer valid. The queue or topic might have become unavailable, the application might be using an incorrect connection for the queue or topic, or the supplied destination is not of the correct type for this method.
我已經完成了如何解決這個問題的研究,但無法達成一個適當的解決方案。