<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">

<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>

                                <td>

                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="https://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>

                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px;  -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
    JMS Client program is not able to receive messages from the queue
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="https://community.jboss.org/people/chithu21">chithu21</a> in <i>JBoss Messaging</i> - <a href="https://community.jboss.org/message/727422#727422">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p>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.</p><p>Can anyone help me please? Thanks in advance.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Client Program:</p><p>----------------------</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>public class MessageReceiver {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; static final int N = 1;</p><p>&#160;&#160;&#160; static CountDown done = new CountDown(N);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; ReadValues readValues = new ReadValues();</p><p>&#160;&#160;&#160; Config config = readValues.readPropertiesFile();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; public static class ExListener implements MessageListener {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; public void onMessage(Message msg) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("Inside OnMessage");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; done.release();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; TextMessage tm = (TextMessage) msg;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; try {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; String receivedMsg = tm.getText();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("onMessage, recv text=" + receivedMsg);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; // System.out.println("Added Some text with " + receivedMsg);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; } catch (Throwable t) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; t.printStackTrace();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160; </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; public void receiveMessage() throws JMSException, NamingException,</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; InterruptedException, ClassNotFoundException, SQLException {</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("Begin receiveMessage method");</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; JMSConnector jmsConnector = new JMSConnector();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; QueueObject queueObj = jmsConnector.setupPTP(config.getProviderUrl(),</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; "XibToCatQueue");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; QueueSession session = queueObj.getQueueSession();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Queue xibToCatQueue = queueObj.getQueue();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("Queue Name : " + xibToCatQueue.getQueueName());</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; // Set the async listener for xibToCatQueue</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; QueueReceiver recv = session.createReceiver(xibToCatQueue);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; //&#160;&#160;&#160; System.out.println("........." + recv.getQueue());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; recv.setMessageListener(new ExListener());&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Queue catToXibQueue = queueObj.getCatToXibQueue();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; QueueSender send = session.createSender(catToXibQueue);</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; String text = "Test Message...";</p><p>&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; TextMessage tm = session.createTextMessage(text);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; tm.setJMSReplyTo(xibToCatQueue);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; send.send(tm);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("Sent text=" + tm.getText());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; send.close();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; MessageReceiver.done.acquire();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; jmsConnector.closePTP();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("End receiveMessage method");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.exit(0);</p><p>&#160;&#160;&#160; }</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160; </p><p>&#160;&#160;&#160;&#160; public static void main(String[] args) throws JMSException,</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; NamingException, InterruptedException, ClassNotFoundException,</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; SQLException {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; MessageReceiver msgReceiver = new MessageReceiver();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; msgReceiver.receiveMessage();</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160; }</p><p>}</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Connector Program:</p><p>---------------------------------</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>public QueueObject setupPTP(String contextUrl,String queueName) throws JMSException, NamingException {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; ReadValues readValues = new ReadValues();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Config config = readValues.readPropertiesFile();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Properties env = new Properties();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; env.put(Context.INITIAL_CONTEXT_FACTORY,config.getContextFactory());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; env.put(Context.PROVIDER_URL, contextUrl);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; env.put(Context.URL_PKG_PREFIXES,config.getPkgPrefixes());</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; InitialContext iniCtx = new InitialContext(env);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Object tmp = iniCtx.lookup("ConnectionFactory");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; connection = qcf.createQueueConnection();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; String lookUpObj = "queue/" + queueName;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Queue xibToCatQueue =&#160; (Queue) iniCtx.lookup(lookUpObj);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; Queue catToXIbQueue = (Queue) iniCtx.lookup("queue/CatToXibQueue");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; connection.start();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; return new QueueObject(session,xibToCatQueue,catToXIbQueue);</p><p>&#160;&#160;&#160; }</p><p>&#160;&#160;&#160; </p><p>&#160;&#160;&#160; public void closePTP() throws JMSException {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; System.out.println("Inside closePTP.....");</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; connection.stop();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if(session != null) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; session.close();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; if(connection != null) {</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; connection.close();</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; }</p><p>&#160;&#160;&#160; }</p></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Reply to this message by <a href="https://community.jboss.org/message/727422#727422">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in JBoss Messaging at <a href="https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2042">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>