0

我编写发布/订阅者示例并将其部署到集群环境中的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 policyHigh availability在websphere总线。 使用Default messaging providerjsp在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(); 
     } 
    } 

} 

回答

0

我通过在WebSphere总线禁用的messaging engine policy解决了这个问题。现在它运作良好。