1

我编写了一个发布/订阅者示例并将其部署在集群环境中的 websphere 应用程序服务器上。但是当我订阅消息时,MDB 只读取了每条消息,并且只读取了一次。我在 websphere 和 MDB 中配置了持久订阅,还设置了Share durable subscriptions toalways sharedAlways activate MDBs in all servers. 每条消息只被阅读一次,我认为它会消耗或其他东西。我@ActivationConfigProperty(propertyName = "useSharedSubscriptionInClusteredContainer",propertyValue = "false")在 MDB 中设置(基于http://docs.oracle.com/cd/E18930_01/html/821-2438/gjzpg.html#MQAGgjzpg),但什么也没发生。我无法在所有服务器中订阅消息。我也将其设置messaging engine policyHigh availabilitywebsphere 总线。被Default messaging provider使用。

哪里有问题??

这是我的出版商

@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();
        }
    }

}
4

1 回答 1

2

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

于 2013-11-17T13:56:41.030 回答