[jboss-user] [JBoss Messaging] - JMS Client program is not able to receive messages from the queue

chithu21 do-not-reply at jboss.com
Fri Mar 30 06:55:14 EDT 2012


chithu21 [https://community.jboss.org/people/chithu21] created the discussion

"JMS Client program is not able to receive messages from the queue"

To view the discussion, visit: https://community.jboss.org/message/727422#727422

--------------------------------------------------------------
I have a jms client program and an MDB. The client program is not able to receive message from the queue. But I am able to see the messages in the MDB's system.out log.
Can anyone help me please? Thanks in advance.

Client Program:
----------------------

public class MessageReceiver {

    static final int N = 1;
    static CountDown done = new CountDown(N);

    ReadValues readValues = new ReadValues();
    Config config = readValues.readPropertiesFile();

    public static class ExListener implements MessageListener {
        public void onMessage(Message msg) {
            System.out.println("Inside OnMessage");
            done.release();
            TextMessage tm = (TextMessage) msg;

            try {
                String receivedMsg = tm.getText();
                System.out.println("onMessage, recv text=" + receivedMsg);
                // System.out.println("Added Some text with " + receivedMsg);

            } catch (Throwable t) {
                t.printStackTrace();
            }
        }

             }



    public void receiveMessage() throws JMSException, NamingException,
            InterruptedException, ClassNotFoundException, SQLException {

        System.out.println("Begin receiveMessage method");

        JMSConnector jmsConnector = new JMSConnector();

        QueueObject queueObj = jmsConnector.setupPTP(config.getProviderUrl(),
                "XibToCatQueue");
        QueueSession session = queueObj.getQueueSession();
        Queue xibToCatQueue = queueObj.getQueue();

        System.out.println("Queue Name : " + xibToCatQueue.getQueueName());

        // Set the async listener for xibToCatQueue
                QueueReceiver recv = session.createReceiver(xibToCatQueue);
            //    System.out.println("........." + recv.getQueue());
                recv.setMessageListener(new ExListener());    


        Queue catToXibQueue = queueObj.getCatToXibQueue();
        QueueSender send = session.createSender(catToXibQueue);


        String text = "Test Message...";

        TextMessage tm = session.createTextMessage(text);
        tm.setJMSReplyTo(xibToCatQueue);
        send.send(tm);
        System.out.println("Sent text=" + tm.getText());
        send.close();


        MessageReceiver.done.acquire();
        jmsConnector.closePTP();

        System.out.println("End receiveMessage method");
        System.exit(0);
    }


     public static void main(String[] args) throws JMSException,
            NamingException, InterruptedException, ClassNotFoundException,
            SQLException {
        MessageReceiver msgReceiver = new MessageReceiver();
        msgReceiver.receiveMessage();

    }
}


Connector Program:
---------------------------------


public QueueObject setupPTP(String contextUrl,String queueName) throws JMSException, NamingException {

        ReadValues readValues = new ReadValues();
        Config config = readValues.readPropertiesFile();
        Properties env = new Properties();
        env.put(Context.INITIAL_CONTEXT_FACTORY,config.getContextFactory());
        env.put(Context.PROVIDER_URL, contextUrl);
        env.put(Context.URL_PKG_PREFIXES,config.getPkgPrefixes());
        InitialContext iniCtx = new InitialContext(env);

        Object tmp = iniCtx.lookup("ConnectionFactory");
        QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;

        connection = qcf.createQueueConnection();
        String lookUpObj = "queue/" + queueName;
        Queue xibToCatQueue =  (Queue) iniCtx.lookup(lookUpObj);
        Queue catToXIbQueue = (Queue) iniCtx.lookup("queue/CatToXibQueue");

        session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        connection.start();



        return new QueueObject(session,xibToCatQueue,catToXIbQueue);
    }

    public void closePTP() throws JMSException {
        System.out.println("Inside closePTP.....");
        connection.stop();
        if(session != null) {
            session.close();
        }
        if(connection != null) {
            connection.close();
        }
    }
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/727422#727422]

Start a new discussion in JBoss Messaging at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2042]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120330/c0305257/attachment-0001.html 


More information about the jboss-user mailing list