OK, Finally got one working usign the default installed example:
Passed the following as JVM arguments:
-Djava.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
-Djava.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
-Djava.naming.provider.url=jnp://localhost:1099
Source:
import javax.jms.ConnectionFactory;
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.Message;
import javax.jms.TextMessage;
//Import the classes to use JNDI.
import javax.naming.*;
public class JbossJmsSendRecv {
/**
* Main method.
*
* @param args not used
*
*/
public static void main(String[] args) {
try {
InitialContext iniCtx = new InitialContext();
ConnectionFactory cf = (ConnectionFactory)
iniCtx.lookup("/ConnectionFactory");
QueueConnectionFactory myQConnFactory =
(QueueConnectionFactory) cf;
QueueConnection conn =
myQConnFactory.createQueueConnection();
QueueSession myQSess =
conn.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);
//QueueSession myQSess = conn.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
Queue myQueue = (Queue)
iniCtx.lookup("/queue/testQueue");
//Create a QueueSender message producer.
QueueSender myQueueSender =
myQSess.createSender(myQueue);
//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();
//Create a QueueReceiver message consumer.
QueueReceiver myQueueReceiver =
myQSess.createReceiver(myQueue);
//Start the QueueConnection created in step 3.
conn.start();
//Receive a message from the queue.
Message msg = myQueueReceiver.receive();
//Retreive the contents of the message.
TextMessage txtMsg = (TextMessage) msg;
System.out.println("Read Message: " + txtMsg.getText());
//Close the session and connection resources.
myQSess.close();
conn.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=3944748#3944748
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3944748
-------------------------------------------------------
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