【问题标题】:jms publish/subscribe in websphere clusterjms 在 websphere 集群中发布/订阅
【发布时间】:2013-11-21 11:52:57
【问题描述】:

我编写了一个发布/订阅者示例并将其部署在集群环境中的 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),但什么也没发生。 我无法在所有服务器中订阅消息。 我还在 websphere 总线中将messaging engine policy 设置为High availability。 使用了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();
        }
    }

}

【问题讨论】:

    标签: jms websphere java-ee-6 publish-subscribe message-driven-bean


    【解决方案1】:

    我通过禁用 websphere 总线中的 messaging engine policy 解决了这个问题。现在效果很好。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-17
      • 1970-01-01
      • 2012-11-02
      • 2013-08-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多