Hi all,

I have the following code work that is running without errors, however the AsynchronousConsumer.java class keeps running without seizing even though the Message Queue has only ten messages. Here is the code:

Java Code:
/**
 * @(#)AsynchronousConsumer.java
 *
 *
 * @author
 * @version 1.00 2011/10/10
 */
 import javax.naming.*;
 import javax.jms.*;
 import java.util.Hashtable;

public class AsynchronousConsumer implements MessageListener
{
 	public static void main(String[] args) throws Exception
 	{
        // TODO code application logic here
        new AsynchronousConsumer().connection();

    }

    public void onMessage(Message message)
    {
		try
		{
			TextMessage msg = null;

			if(message instanceof TextMessage)
			{
				msg = (TextMessage) message;

				String text = msg.getText();

				while(text != null)
				{
					if(text == null)
					{
						break;
					}
					else
					{
						System.out.println(msg.getText());
						msg = (TextMessage)message;
						text = msg.getText();
					}
				}
			}
		}
		catch (JMSException jme)
		{
			jme.printStackTrace();
		}
    }

    public void connection() throws Exception
    {
    	Hashtable<String, String> env = new Hashtable<String, String>();

    	env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
    	env.put(Context.PROVIDER_URL, "file:///C:/imq_admin_objects");

    	Context ctx = new InitialContext(env);

    	ConnectionFactory conFactory = (ConnectionFactory)ctx.lookup("MyConnectionFactory");
    	Connection connection = conFactory.createConnection();

    	Destination myDest = (Destination)ctx.lookup("MyDest");

    	Session mySession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    	MessageConsumer consumer = mySession.createConsumer(myDest);

		consumer.setMessageListener(this);
    	connection.start();

		Message message = mySession.createTextMessage();

		onMessage(message);

		connection.close();
    }
}
this is the AsynchronousConsumer class as you can see
Now for the Producer class

Java Code:
import javax.jms.*;
import java.util.*;
import javax.naming.*;

public class MyProducer
{

    public static void main(String[] args)
    {
        // TODO code application logic here
        try
        {
        	new MyProducer().createConnection();
        }
        catch (Exception e)
        {
        	e.printStackTrace();
        }
    }

    public void createConnection() throws Exception
    {
    	Hashtable<String, String> evn = new Hashtable<String, String>();

    	evn.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
    	evn.put(Context.PROVIDER_URL, "file:///C:/imq_admin_objects");

    	Context ctx = new InitialContext(evn);

    	ConnectionFactory connFactory = (ConnectionFactory)ctx.lookup("MyConnectionFactory");
    	Connection connection = connFactory.createConnection();

    	Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    	Destination mydest = (Destination)ctx.lookup("MyDest");

    	MessageProducer producer = session.createProducer(mydest);

    	TextMessage msg = session.createTextMessage();

    	for(int i = 0; i < 10; i++)
    	{
    		msg.setText("This is message " + (i + 1));
    		System.out.println("Sending message " + (i+1));

    		producer.send(msg);
    	}

    	producer.send(session.createMessage());

	/*	msg.setText("Sending message ");
		System.out.println(msg.getText());
		producer.send(msg);*/

    	connection.close();
    }
}
I for one do not see the problem since I used condition statement to run it (refer AsynchronousConsumer.java)

Thanks in advance

Kind regards
Dark-Redd