I usr WSO2 MB 2.0.1,我嘗試將本教程提供的JMS Java訂閱者擴展爲 作爲持久訂閱者。 然後停止jms客戶端並向主題發送一些消息。但是當我 啓動jms客戶端時,它不會收到消息。如何爲WSO2中的主題創建持久訂閱者MB
有人可以讓我知道如何創建一個持久的訂戶。 我的要求是當jms用戶上線時收到消息。
我的代碼: 公共無效認購(字符串topicName){
Properties initialContextProperties = new Properties();
initialContextProperties.put("java.naming.factory.initial",
"org.wso2.andes.jndi.PropertiesFileInitialContextFactory");
String connectionString = "amqp://admin:[email protected]/carbon?brokerlist='tcp://localhost:5672'";
initialContextProperties.put("connectionfactory.qpidConnectionfactory", connectionString);
initialContextProperties.put("topic.myWarning", "myWarning");
try {
InitialContext initialContext = new InitialContext(initialContextProperties);
TopicConnectionFactory topicConnectionFactory =
(TopicConnectionFactory) initialContext.lookup("qpidConnectionfactory");
TopicConnection topicConnection = topicConnectionFactory.createTopicConnection();
//topicConnection.setClientID("clientID");
topicConnection.start();
TopicSession topicSession =topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
//Topic topic = topicSession.createTopic(topicName);
Topic topic =(Topic) initialContext.lookup(topicName);
TopicSubscriber topicSubscriber =
topicSession.createDurableSubscriber(topic, "tom");
TextMessage receivedMessage = (TextMessage)topicSubscriber.receive();
System.out.println(receivedMessage);
// topicSubscriber.setMessageListener(new JCOMessageListener(
// topicConnection, topicSession, topicSubscriber));
} catch (NamingException e) {
e.printStackTrace();
} catch (JMSException e) {
e.printStackTrace();
}
}
運行樣本代碼,爲什麼報文丟失?這是DurableSubscriber – user1865153