Hi - Can anyone please tell me step by step, how to set up my pc, Sun application server and program to use JMS. I have been trying to send messages between applications but I keep getting exceptions, mostly class not found. I have been adding JARs from my application server directory in my application CLASSPATH but I keep getting more and more exceptions. Can someone also explain to me how to set up connection factories etc in the Application server?
Regards Alfred
bhaswar goswami
Greenhorn
Joined: Jul 04, 2005
Posts: 14
posted
0
Hey listen , i am giving u some code that connects to the JBOSS-MQ and publishes some messages to the queue-D .
If u want to connect to some other Appserver then u need to change only the initial context factory i.e ( the getProperties()- method in the code. to run the code u need to have some jar in the CLASSPATH and run the Jboss server & then run the Code .
The code is as follows : --------------------------------------------------------------
// Get the initial context with given properties System.out.println("Before creating the Initial Context.."); try { context = new InitialContext( properties); } catch (NamingException e) { System.out.println("Exception while gettin the Context");
e.printStackTrace(); }
//Get the connection factory try { queueFactory = (QueueConnectionFactory)context.lookup("ConnectionFactory"); System.out.println("Received the Factory from context.."); } catch (NamingException e) { System.out.println("Exception while getting the Factory");
e.printStackTrace(); } try { queueConnection = queueFactory.createQueueConnection(); System.out.println("Created the Queue Connection .."); } catch (JMSException e) { System.out.println("Exception while Creating the QueueConnection");
e.printStackTrace(); }
try { queueSession = queueConnection.createQueueSession( false, Session.AUTO_ACKNOWLEDGE); System.out.println("Created the Session On the created connection .."); } catch (JMSException e) { System.out.println("Exception while Creating the Session On the created connection .."); e.printStackTrace(); } try { queue = queueSession.createQueue("D"); System.out.println("Created the Queue on the session"); } catch (JMSException e) { System.out.println("Exception while creating the Queue On session .."); e.printStackTrace(); } try { sender = queueSession.createSender( queue ); System.out.println("the Sender Has been created to the Test Queue"); } catch (JMSException e) { System.out.println("Exception while creating the Sender"); e.printStackTrace(); }
TextMessage message = null; int i = 1; while( i<=2){