Question

I write a publish/subscriber sample and deploy it on websphere application server in cluster environment. but when I subscribe the message, each message only and only one time was read by MDB. I configured durable subscription in websphere and MDB, also I set the Share durable subscriptions to always shared and set the Always activate MDBs in all servers. each message was read only one time, I think it consumes or something else. I set the @ActivationConfigProperty(propertyName = "useSharedSubscriptionInClusteredContainer",propertyValue = "false") in MDB (based on http://docs.oracle.com/cd/E18930_01/html/821-2438/gjzpg.html#MQAGgjzpg), but nothing happened. I can not subscribe messages in all servers. Also i set the messaging engine policy to High availability in the websphere bus. the Default messaging provider is used.

where is the problem??

here is my publisher

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

    }
}

and my subscriber

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

}
Was it helpful?

Solution

I resolved the problem by disabling the messaging engine policy in the websphere bus. Now it works well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top