所以我试图通过带有消息Id选择器的JMS来消费来自Tibco EMS代理的消息。如果消息是NON_PERSISTENT,我可以通过它们的JMSMessageID来选择它们,并且一切正常。
如果消息是PERSISTENT,则选择器不会检索任何内容。我在Apache ActiveMQ上尝试了相同的代码,它在两种情况下都有效。我已经通过EMS样品,看不到任何明显的东西。想知道是否有一些EMS设置可能会影响这个......
如果省略选择器,则无论DeliveryMode如何,都会正确使用消息。
这是我用来复制它的内容。
非常感谢任何帮助:)
package com;
import javax.jms.*;
import com.tibco.tibjms.TibjmsConnectionFactory;
public class JMSTest {
String msgIdPersistent = "";
String msgIdNon_Persistent = "";
String serverUrl = "tcp://localhost:7222";
String queueName = "test";
public static void main(String[] args) {
JMSTest test = new JMSTest();
try {
test.publish();
test.deleteBySelector();
}catch(Exception ex) {
ex.printStackTrace();
}
}
public void deleteBySelector() throws Exception {
// Create connection and session
ConnectionFactory factory = new TibjmsConnectionFactory(serverUrl);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession();
// Delete non-persistent
//
String selectorNonPersist = "JMSMessageID='" + msgIdNon_Persistent + "'";
MessageConsumer nonPersistReceiver = session.createConsumer(session.createQueue(queueName), selectorNonPersist);
Message nonPersistMsg = null;
nonPersistMsg = nonPersistReceiver.receive(1000);
System.out.println("NON PERSISTENT SELECTOR: " + ((nonPersistMsg!=null) ? "SUCCESS" : "FAIL"));
// Delete Persistent - **** THIS DOESN'T WORK *****
//
String selectorPersist = "JMSMessageID='" + msgIdPersistent + "'";
MessageConsumer persistReceiver = session.createConsumer(session.createQueue(queueName), selectorPersist);
Message persistMsg = null;
persistMsg = persistReceiver.receive(1000);
System.out.println("PERSISTENT SELECTOR: " + ((persistMsg!=null) ? "SUCCESS" : "FAIL"));
}
public void publish() throws Exception {
ConnectionFactory factory = new com.tibco.tibjms.TibjmsConnectionFactory(serverUrl);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(javax.jms.Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("test");
// Send persistent message
//
System.out.println("Persistent publish");
MessageProducer producerPersistent = session.createProducer(null);
producerPersistent.setDeliveryMode(DeliveryMode.PERSISTENT);
TextMessage messagePersistent = session.createTextMessage("PERSISTENT");
producerPersistent.send(destination, messagePersistent);
msgIdPersistent = messagePersistent.getJMSMessageID();
System.out.println("\tMsgId=" + msgIdPersistent);
// Send Non Persistent message
//
System.out.println("NON Persistent publish");
MessageProducer producernonPersistent = session.createProducer(destination);
producernonPersistent.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
TextMessage messageNonPersistent = session.createTextMessage("NON_PERSISTENT");
producernonPersistent.send(messageNonPersistent);
msgIdNon_Persistent = messageNonPersistent.getJMSMessageID();
System.out.println("\tMsgId=" + msgIdNon_Persistent);
// Clean up
session.close();
connection.close();
System.out.println("Done publish\n");
}
}
我从中获得的输出是:
Persistent publish
MsgId=ID:EMS-SERVER.3D856ECE827932:1
NON Persistent publish
MsgId=ID:EMS-SERVER.3D856ECE827932:2
Done publish
NON PERSISTENT SELECTOR: SUCCESS
PERSISTENT SELECTOR: FAIL
答案 0 :(得分:1)
我已经在8.2.x中确认了它的错误。我升级到8.3.x并且工作正常。