[jboss-dev-forums] [Design of Messaging on JBoss (Messaging/JBoss)] - Problem in running the JMS program in JbossMq

milinduc do-not-reply at jboss.com
Sat Jul 22 07:53:32 EDT 2006


I am completely new to jbossmq I got the probel in running  jmms programs. Herer I created the two jms files one is message to que and que to message.



message to que:->

           

package src.jms;
import javax.jms.*;
import javax.naming.*;

import java.util.Hashtable;
import java.util.Properties;


public class MessageToQueue 
{
	public static void main(String[] args)
	{
		
		QueueConnectionFactory cf;
		QueueConnection connection;
		QueueSession session;
		Queue destination;
		QueueSender sender;
		TextMessage message;

		Hashtable env = new Hashtable();
		  env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
		  env.put(Context.PROVIDER_URL,	"localhost:1199");
		  
		try {
			Context ctx = new InitialContext(env);
		

		/* ctx = new InitialContext(); */
			cf = (QueueConnectionFactory) ctx.lookup("/ConnectionFactory");			destination = (Queue)ctx.lookup("queue/testQueue");
		connection = cf.createQueueConnection();
		session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
		sender = session.createSender(destination);
		message = session.createTextMessage();
		message.setText("Hello World!");

		System.out.println("Sending Message.");
		sender.send(message);

		connection.close();
		System.out.println("Done.");
	}
		 catch (NamingException e) {
		
				e.printStackTrace();
			}
		 
		 catch (JMSException e) {
			
				e.printStackTrace();
			}
	}
}



que to message:->



package src.jms;
import javax.jms.*;

import java.util.Hashtable;
import java.util.Properties;
import javax.naming.*;

/**
 * Receives a TextMessage from a Queue
 */
public class QueueToMessage 
{
	public static void main(String[] args) 
	{

		QueueConnectionFactory cf;
		QueueConnection connection;
		QueueSession session;
		Queue destination;
		QueueReceiver receiver;
		TextMessage message;
		
		Hashtable env = new Hashtable();
		  env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
		  env.put(Context.PROVIDER_URL,	"172.24.1.226:1199");
		  try {
				Context ctx = new InitialContext(env);
			cf = (QueueConnectionFactory) ctx.lookup("/ConnectionFactory");
			destination = (Queue) ctx.lookup("queue/testQueue");

		connection = cf.createQueueConnection();
		session = connection
				.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
		receiver = session.createReceiver(destination);

		System.out.println("Waiting For A Message.");
		connection.start();
		message = (TextMessage) receiver.receive();
		System.out.println("The message was: " + message.getText());

		connection.close();
		System.out.println("Done.");
}
catch(JMSException e){
	e.printStackTrace();
}


catch(NamingException e){
	e.printStackTrace();
}
	}
}



Here I am geeting th  forllowing error as :->




log4j:WARN No appenders could be found for logger (org.jnp.interfaces.NamingContext).
log4j:WARN Please initialize the log4j system properly.
javax.naming.CommunicationException: Receive timed out [Root exception is java.net.SocketTimeoutException: Receive timed out]
	at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1302)
	at org.jnp.interfaces.NamingContext.checkRef(NamingContext.java:1382)
	at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:579)
	at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:572)
	at javax.naming.InitialContext.lookup(Unknown Source)
	at src.jms.MessageToQueue.main(MessageToQueue.java:30)
Caused by: java.net.SocketTimeoutException: Receive timed out
	at java.net.PlainDatagramSocketImpl.receive(Native Method)
	at java.net.DatagramSocket.receive(Unknown Source)
	at org.jnp.interfaces.NamingContext.discoverServer(NamingContext.java:1272)
	... 5 more


I am trying hard to solve this error but I am  not abel to solve this erroe.So please tell me how to run this program.
and tell em in which xml files I needd to specify the JNDI name for connection factory and where I need to put this line.


Also tell em how to use the jms1.0  and ant  usiing jboss.






View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3960101#3960101

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3960101



More information about the jboss-dev-forums mailing list