我編寫發佈/訂閱者示例並將其部署到集羣環境中的websphere應用程序服務器上。 但是當我訂閱消息時,每條消息只有一次被MDB讀取。 我在websphere和MDB中配置了持久訂閱,同時我將Share durable subscriptions
設置爲always shared
並設置了Always activate MDBs in all servers
。每個消息只讀一次,我認爲它消耗或其他東西。 我在MDB中設置了@ActivationConfigProperty(propertyName = "useSharedSubscriptionInClusteredContainer",propertyValue = "false")
(根據http://docs.oracle.com/cd/E18930_01/html/821-2438/gjzpg.html#MQAGgjzpg),但沒有任何發生。 我無法在所有服務器中訂閱消息。 我還設置messaging engine policy
到High availability
在websphere總線。 使用Default messaging provider
。jsp在websphere集羣中發佈/訂閱
問題在哪裏?
這裏是我的出版商
@WebServlet("/publishServlet")
public class Testpublish extends HttpServlet {
@Resource(mappedName = "jms/ConnFact")
private static TopicConnectionFactory topicConnectionFactory;
@Resource(mappedName = "jms/topicJ")
private static Topic topic;
TopicConnection connection = null;
TopicSession session = null;
TopicPublisher publisher = null;
TextMessage message = null;
final int NUM_MSGS = 5;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/plain");
ServletOutputStream out = response.getOutputStream();
out.println("Start Testing");
System.out.println("Start Testing");
try {
connection = topicConnectionFactory.createTopicConnection();
session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
publisher = session.createPublisher(topic);
message = session.createTextMessage();
for (int i = 0; i < NUM_MSGS; i++) {
message.setText("This is testMessage " + (i + 1));
System.out.println("Sending testMessage: " + message.getText());
out.println("Sending testMessage: " + message.getText());
publisher.publish(message);
}
connection.close();
out.println("Finish Testing");
System.out.println("Finish Testing");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
和我的用戶
@MessageDriven(mappedName = "jms/topicJ", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "subscriptionDurability",propertyValue = "Durable"),
@ActivationConfigProperty(propertyName = "clientId",propertyValue = "MyID"),
@ActivationConfigProperty(propertyName = "subscriptionName",propertyValue = "MySub")
})
public class testsubscribe implements MessageListener {
@Override
public void onMessage(Message message) {
TextMessage txtMessage = (TextMessage) message;
try {
System.out.println("---------MESSAGE RECIEVED------------" + txtMessage.getText()
+ " ..............");
} catch (JMSException e) {
e.printStackTrace();
}
}
}