users@glassfish.java.net

JMS Q Listner (MDB) Problem

From: <glassfish_at_javadesktop.org>
Date: Thu, 15 Oct 2009 05:53:03 PDT

hi gurus,

 i have a problem with MDB. my scenario is i need two JMS Queues and two listners for the queues. for that i have created two connection factories and two destination resources in glasshfish admin console.

Connection Factories:1.jms/testfact1
                                2.jms/testfact2

Destination Resources 1.jms/testdest1
                                  2.jms/testdest2

MDB 1:

@MessageDriven(mappedName = "jms/testdest1", activationConfig = {
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
    })


public class MDB1 MessageListener {

 public void onMessage(Message message) {
        try {
            TextMessage text=(TextMessage)message;
           System.out.println("message has received-->"+text.getText());
       } catch (Exception ex) {
            Logger.getLogger(TestMessageDrivenBean.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

MDB 2:

@MessageDriven(mappedName = "jms/testdest2", activationConfig = {
        @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
        @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
    })


public class MDB2 MessageListener {

 public void onMessage(Message message) {
        try {
            TextMessage text=(TextMessage)message;
           System.out.println("message has received-->"+text.getText());
       } catch (Exception ex) {
            Logger.getLogger(TestMessageDrivenBean.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

Client 1

public class ProcessQueueJMS implements ProcessInvokerRemote {

  @Resource(mappedName = "jms/testfact1")
    private ConnectionFactory connectionFactory;
    @Resource(mappedName = "jms/testdest1")
    private Queue queue;

public void run(String str){


            Connection connection = connectionFactory.createConnection();
            javax.jms.Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            javax.jms.MessageProducer messageProducer = session.createProducer(queue);
            ObjectMessage message = session.session.createTextMessage();
            message.setText(str);
            message.setJMSType(obj[0].toString());
            messageProducer.send(message);

}
}



Client 2

public class ProcessQueueJMS11 implements ProcessInvokerRemote {

  @Resource(mappedName = "jms/testfact2")
    private ConnectionFactory connectionFactory;
    @Resource(mappedName = "jms/testdest2")
    private Queue queue;

public void run(String str){


            Connection connection = connectionFactory.createConnection();
            javax.jms.Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
            javax.jms.MessageProducer messageProducer = session.createProducer(queue);
            ObjectMessage message = session.session.createTextMessage();
            message.setText(str);
            message.setJMSType(obj[0].toString());
            messageProducer.send(message);

}
}


PROBLEM IS WHEN I EXECUTE CLINT1 , SOMETIMES THE MDB1 IS RECEIVING THE MESSAGE AND SOME TIMES MDB2 IS RECEIVING MESSAGE. SAME WITH CLIENT 2 ALSO.......PLS HELP ME TWO RESOLVE THIS PROBLEM

REGARDS
GURU...
[Message sent by forum member 'guruvulubojja' (guruvulubojja_at_gmail.com)]

http://forums.java.net/jive/thread.jspa?messageID=368034