I could find any simple self-contained JMS examples without JNDI using JBoss,
so I grabbed an example from Sun's JMS site, and am wondering what connection
information is needed to make this work with JBoss JMS? I have JBoss installed
and the example queue working with the ant script. I am excited about an open
source JMS implementation, but could use a little help.
Regards,
ed
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueConnection;
import javax.jms.QueueSession;
import javax.jms.QueueSender;
import javax.jms.QueueReceiver;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.Message;
import javax.jms.TextMessage;
//Import the classes to use JNDI.
import javax.naming.*;
import java.util.*;
public class JbossJmsSendRecv {
/**
* Main method.
*
* @param args not used
*
*/
public static void main(String[] args) {
try {
QueueConnectionFactory myQConnFactory;
Queue myQueue;
//This statement can be eliminated if the JNDI code above is used.
myQConnFactory = new com.sun.messaging.QueueConnectionFactory();
//Step 3:
//Create a connection to the Sun Java(tm) System Message Queue
Message
//Service.
QueueConnection myQConn = myQConnFactory.createQueueConnection();
//Step 4:
//Create a session within the connection.
QueueSession myQSess = myQConn.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
//Step 5:
//Instantiate a Sun Java(tm) System Message Queue Destination
//administered object.
myQueue = new com.sun.messaging.Queue("world");
//Step 6:
//Create a QueueSender message producer.
QueueSender myQueueSender = myQSess.createSender(myQueue);
//Step 7:
//Create and send a message to the queue.
TextMessage myTextMsg = myQSess.createTextMessage();
myTextMsg.setText("Hello World");
myQueueSender.send(myTextMsg);
System.out.println("Message sent");
//session.commit();
//Step 8:
//Create a QueueReceiver message consumer.
QueueReceiver myQueueReceiver = myQSess.createReceiver(myQueue);
//Step 9:
//Start the QueueConnection created in step 3.
myQConn.start();
//Step 10:
//Receive a message from the queue.
Message msg = myQueueReceiver.receive();
//Step 11:
//Retreive the contents of the message.
TextMessage txtMsg = (TextMessage) msg;
System.out.println("Read Message: " + txtMsg.getText());
//Step 12:
//Close the session and connection resources.
myQSess.close();
myQConn.close();
} catch (Exception jmse) {
System.out.println("Exception occurred : " + jmse.toString());
jmse.printStackTrace();
}
}
}
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3943979#3943979
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3943979
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user