users@glassfish.java.net

Re: Simple JMS Client doesn't quit

From: <glassfish_at_javadesktop.org>
Date: Wed, 19 Mar 2008 05:33:22 PST

I have the same problem as whartung. First I followed the advice of rampsarathy. I also found that the parameters he describes are found in glassfish\domains\domain1\config\domain.xml

I restarted the server several times, to be on the safe side. But it does not help.

My client runs standalone. My server is GlassFish V2. The client can get the queue and connectionfactory from JNDI, send a message and then hangs.

GlassFish logs an error.
[i]DirectConsumer:Caught Exception delivering messagecom.sun.messaging.jmq.io.Packet|#][/i]

Despite the error, the MDB continues and logs fine.

Before the client hangs it even logs this message:
[i]Mar 19, 2008 1:32:38 PM com.sun.enterprise.resource.AbstractResourcePool performMaxConnectionUsageOperation
INFO: RAR7113: destroying connection since it has reached the maximum usage of : 1[/i]

So it seams that the connection is gone, but the client still hangs! Of course I can stop it with System.exit() but that I consider hacking.
Several years ago I tried this on JBoss 4 and EJB 2.1. I never met these kind of weird undocumented problems with JBoss and that is frustrating :-)

My questions
1. What should I do to make a simple client?
2. Must I always send a reply from the MDB back to the client?

Here is my code to illustrate my problem.

[b]Client:[/b]

    public static void main(String[] args) throws Exception
    {
        InitialContext context = new InitialContext();
        ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup("jms/JEECourseConnectionFactory");
        Queue queue = (Queue) context.lookup("jms/JEECourseDownstreamQueue");

        Connection connection = connectionFactory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageProducer messageProducer = session.createProducer(queue);

        TextMessage message = session.createTextMessage("This is a client request");
        messageProducer.send(message);
        
        messageProducer.close();
        session.close();
        connection.close();
        
        System.out.println("Message sent successfully");
    
        //System.exit(0);
    }

[b]Server (MDB)[/b]

@MessageDriven(mappedName="jms/JEECourseDownstreamQueue")
public class LongOperationMessageBean implements MessageListener
{
    private static final Logger logger = Logger.getLogger(LongOperationMessageBean.class.getName());
    
    public void onMessage(Message message)
    {
        try
        {
            logger.info("Received a message from the downstream queue");
            TextMessage textMessage = (TextMessage)message;
            log(textMessage);
        }
        catch (Exception exception)
        {
            logger.log(Level.SEVERE, exception.getMessage(), exception);
        }
        
    }
    
    private void log(TextMessage message) throws JMSException
    {
        logger.info("\tTime: " + System.currentTimeMillis() + " ms");
        logger.info("\tMessage ID: " + message.getJMSMessageID());
        logger.info("\tCorrel. ID: " + message.getJMSCorrelationID());
        logger.info("\tReply to: " + message.getJMSReplyTo());
        logger.info("\tContents: " + message.getText());
    }
}

[b]GlassFish Server log[/b]
[#|2008-03-19T14:14:49.318+0100|INFO|sun-appserver9.1|javax.enterprise.system.core.classloading|_ThreadID=15;_ThreadName=httpWorkerThread-4848-0;Exercise7_MDB;|LDR5010: All ejb(s) of [Exercise7_MDB] loaded successfully!|#]

[#|2008-03-19T14:14:54.708+0100|INFO|sun-appserver9.1|javax.resourceadapter.mqjmsra.outbound.connection|_ThreadID=18;_ThreadName=p: thread-pool-1; w: 5;|MQJMSRA_MF1101: setPassword:NOT setting default value|#]

[#|2008-03-19T14:14:54.708+0100|INFO|sun-appserver9.1|javax.resourceadapter.mqjmsra.outbound.connection|_ThreadID=18;_ThreadName=p: thread-pool-1; w: 5;|MQJMSRA_MF1101: setAddressList:NOT setting default value=localhost|#]

[#|2008-03-19T14:14:54.708+0100|INFO|sun-appserver9.1|javax.resourceadapter.mqjmsra.outbound.connection|_ThreadID=18;_ThreadName=p: thread-pool-1; w: 5;|MQJMSRA_MF1101: setUserName:NOT setting default value=guest|#]

[#|2008-03-19T14:14:56.974+0100|INFO|sun-appserver9.1|javax.enterprise.system.stream.out|_ThreadID=19;_ThreadName=Session266021096732120577;|
DirectConsumer:Caught Exception delivering messagecom.sun.messaging.jmq.io.Packet|#]

[#|2008-03-19T14:14:57.099+0100|INFO|sun-appserver9.1|com.xxx.jeecourse.exercise7.LongOperationMessageBean|_ThreadID=18;_ThreadName=p: thread-pool-1; w: 5;|Received a message from the downstream queue|#]

[#|2008-03-19T14:14:57.099+0100|INFO|sun-appserver9.1|com.xxx.jeecourse.exercise7.LongOperationMessageBean|_ThreadID=18;_ThreadName=p: thread-pool-1; w: 5;| Time: 1205932497099 ms|#]

[#|2008-03-19T14:14:57.099+0100|INFO|sun-appserver9.1|com.xxx.jeecourse.exercise7.LongOperationMessageBean|_ThreadID=18;_ThreadName=p: thread-pool-1; w: 5;| Message ID: ID:12-136.225.5.127(e8:6b:65:c7:e5:3c)-3252-1205932496818|#]

[#|2008-03-19T14:14:57.099+0100|INFO|sun-appserver9.1|com.xxx.jeecourse.exercise7.LongOperationMessageBean|_ThreadID=18;_ThreadName=p: thread-pool-1; w: 5;| Correl. ID: null|#]

[#|2008-03-19T14:14:57.099+0100|INFO|sun-appserver9.1|com.xxx.jeecourse.exercise7.LongOperationMessageBean|_ThreadID=18;_ThreadName=p: thread-pool-1; w: 5;| Reply to: null|#]

[#|2008-03-19T14:14:57.099+0100|INFO|sun-appserver9.1|com.xxx.jeecourse.exercise7.LongOperationMessageBean|_ThreadID=18;_ThreadName=p: thread-pool-1; w: 5;| Contents: This is a client request|#]
[Message sent by forum member 'jooper' (jooper)]

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