sir, you are a very big programmer.
my problem has been solved. everything is working fine.
thank you.
may be someday someone may want to learn JMS i am sharing my full code snippet
here..
first start your Jboss server and then .....
To Send a message
==================
| import java.util.Hashtable;
|
| import javax.jms.JMSException;
| import javax.jms.Queue;
| import javax.jms.QueueConnection;
| import javax.jms.QueueConnectionFactory;
| import javax.jms.QueueSender;
| import javax.jms.QueueSession;
| import javax.jms.Session;
| import javax.jms.TextMessage;
| import javax.naming.Context;
| import javax.naming.InitialContext;
| import javax.naming.NamingException;
|
| public class QueueSend
| {
| public static void main(String[] args)
| {
| try
| {
| // create a JNDI context
| Hashtable env = new Hashtable();
| env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
| env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
| env.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interfaces");
| Context context = new InitialContext(env);
|
|
| // retrieve queue connection factory
| QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory)context.lookup("ConnectionFactory");
| // create a queue connection
| QueueConnection queueConnection =
queueConnectionFactory.createQueueConnection();
|
| // create a queue session
| // set transactions to false and set auto
acknowledgement of receipt of messages
| QueueSession queueSession =
queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
|
| // retrieve queue
| Queue queue = (Queue)context.lookup("queue/A");
|
| // create a queue sender and associate to the retrieved
queue
| QueueSender queueSender =
queueSession.createSender(queue);
|
| // send a message to the queue
| TextMessage message = queueSession.createTextMessage();
| message.setText("Hello there.");
| queueSender.send(message);
|
| System.out.println("Sample application writing message
to queue.");
|
| // clean up
| queueSender.close();
| queueSession.close();
| queueConnection.close();
|
| }
| catch (NamingException e)
| {
| e.printStackTrace();
| }
| catch (JMSException e)
| {
| e.printStackTrace();
| }
|
|
| }
| }
|
|
|
compile it
==========
javac -classpath .;e:\j2ee.jar;c:\jboss\client\jbossall-client.jar
QueueSend.java ===>compiles
run it
========
java -classpath .;e:\j2ee.jar;c:\jboss\client\jbossall-client.jar
QueueSend
Sample application writing message to queue.
To Receive a message Synchronously
====================================
|
| import java.util.Hashtable;
|
| import javax.jms.JMSException;
| import javax.jms.Queue;
| import javax.jms.QueueConnection;
| import javax.jms.QueueConnectionFactory;
| import javax.jms.QueueReceiver;
| import javax.jms.QueueSession;
| import javax.jms.Session;
| import javax.jms.TextMessage;
| import javax.jms.Message;
| import javax.naming.Context;
| import javax.naming.InitialContext;
| import javax.naming.NamingException;
|
|
| public class QueueReceiveSynchronous
| {
| public static void main(String[] args)
| {
| try
| {
| // standard boilerplate code to establish a JNDI
| // context and connection
|
| Hashtable env = new Hashtable();
| env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
| env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
| env.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interfaces");
| Context context = new InitialContext(env);
|
| // retrieve queue connection factory
| QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory)context.lookup("ConnectionFactory");
|
|
|
| // create a queue connection
| QueueConnection queueConnection =
| queueConnectionFactory.createQueueConnection();
|
| // start delivery of incoming messages
| queueConnection.start();
|
| // create a queue session
| // set transactions to false and set auto
| // acknowledgement of receipt of messages
| QueueSession queueSession =
| queueConnection.createQueueSession(
| false,Session.AUTO_ACKNOWLEDGE);
|
| // retrieve queue
| Queue queue =
| (Queue)context.lookup("queue/A");
|
| // create a queue receiver and associate
| // to the retrieved queue
| QueueReceiver queueReceiver =
| queueSession.createReceiver(queue);
|
| // receive message using the synchronous
| // receive method
| Message message = queueReceiver.receive();
| String messageText = null;
| if (message instanceof TextMessage)
| messageText =
| ((TextMessage)message).getText();
| System.out.println(messageText);
|
| // clean up
| queueReceiver.close();
| queueSession.close();
| queueConnection.close();
|
| }
| catch (NamingException e)
| {
| e.printStackTrace();
| }
| catch (JMSException e)
| {
| e.printStackTrace();
| }
| }
| }
|
compile it
==========
javac -classpath .;e:\j2ee.jar;c:\jboss\client\jbossall-client.jar
QueueReceiveSynchronous.java===>compiles fine
Run it
======
java -classpath .;e:\j2ee.jar;c:\jboss\client\jbossall-client.jar
QueueReceiveSynchronous
Hello there.
To Receive the mesasage Asynchronously
=======================================
| import java.util.Hashtable;
|
| import javax.jms.JMSException;
| import javax.jms.Message;
| import javax.jms.MessageListener;
| import javax.jms.Queue;
| import javax.jms.QueueConnection;
| import javax.jms.QueueConnectionFactory;
| import javax.jms.QueueReceiver;
| import javax.jms.QueueSession;
| import javax.jms.Session;
| import javax.jms.TextMessage;
| import javax.naming.Context;
| import javax.naming.InitialContext;
| import javax.naming.NamingException;
|
| public class QueueReceiveAsynchronous implements MessageListener
| {
|
| private QueueConnection queueConnection;
| private QueueSession queueSession;
| private Queue queue;
| private QueueReceiver queueReceiver;
|
| QueueReceiveAsynchronous()
| {
| try
| {
| // create a JNDI context
| Hashtable env = new Hashtable();
| env.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
| env.put(Context.PROVIDER_URL, "jnp://localhost:1099");
| env.put(Context.URL_PKG_PREFIXES,
"org.jboss.naming:org.jnp.interfaces");
| Context context = new InitialContext(env);
|
| // retrieve queue connection factory
| QueueConnectionFactory queueConnectionFactory =
(QueueConnectionFactory)context.lookup("ConnectionFactory");
|
| // create a queue connection
| queueConnection =
| queueConnectionFactory.createQueueConnection();
|
| // create a queue session
| // set transactions to false and set auto
| // acknowledgement of receipt of messages
| queueSession = queueConnection.createQueueSession(
| false,Session.AUTO_ACKNOWLEDGE);
|
| // retrieve queue
| queue = (Queue)context.lookup("queue/A");
|
| // create a queue receiver and associate
| // to the retrieved queue
| queueReceiver = queueSession.createReceiver(queue);
|
| // associate message listener
| queueReceiver.setMessageListener(this);
|
| // start delivery of incoming messages
| queueConnection.start();
| }
| catch (NamingException e)
| {
| e.printStackTrace();
| }
| catch (JMSException e)
| {
| e.printStackTrace();
| }
| }
|
| public static void main(String[] args)
| {
| System.out.println(
| "Example to asynchronously listen to a queue.");
| try
| {
| QueueReceiveAsynchronous listener =
| new QueueReceiveAsynchronous();
| Thread.currentThread().sleep(2000);
| }
|
| catch (InterruptedException e)
| {
| e.printStackTrace();
| }
| }
|
| // process incoming messages
| public void onMessage(Message message)
| {
| try
| {
| String messageText = null;
| if (message instanceof TextMessage)
| messageText = ((TextMessage)message).getText();
| System.out.println(messageText);
| }
| catch (JMSException e)
| {
| e.printStackTrace();
| }
| }
| }
|
compile it
===========
javac -classpath .;e:\j2ee.jar;c:\jboss\client\jbossall-client.jar
QueueReceiveAsynchronous.java ==>compiles fine.
Run it
======
| java -classpath .;e:\j2ee.jar;c:\jboss\client\jbossall-client.jar
| QueueReceiveAsynchronous
| Example to asynchronously listen to a queue.
| Hello there.
|
ALL thsese works.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3906531#3906531
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3906531
-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user