Problem with  SimpleQueueSender

10-11  Source: Network gathering  Views:0 

Advertisement
Have tried SimpleQueueSender seems that message is null.
Queue is set to MyQueue so its not null but
message =queueSession.createTextMessage();
always yields a null value .
Please help
=================== Code -======================
import javax.jms.*;
import javax.naming.*;
public class SimpleQueueSender {
* Main method.
* @param args the queue used by the example and,
* optionally, the number of messages to send
public static void main(String[] args) {
String queueName = null;
Context jndiContext = null;
QueueConnectionFactory queueConnectionFactory = null;
QueueConnection queueConnection = null;
QueueSession queueSession = null;
Queue queue = null;
QueueSender queueSender = null;
TextMessage message = null;
final int NUM_MSGS;
if ( (args.length < 1) || (args.length > 2) ) {
System.out.println("Usage: java SimpleQueueSender " +
"<queue-name> [<number-of-messages>]");
System.exit(1);
queueName = new String(args[0]);
System.out.println("Queue name is " + queueName);
if (args.length == 2){
NUM_MSGS = (new Integer(args[1])).intValue();
} else {
NUM_MSGS = 1;
* Create a JNDI API InitialContext object if none exists
* yet.
try {
jndiContext = new InitialContext();
} catch (NamingException e) {
System.out.println("Could not create JNDI API " +
"context: " + e.toString());
System.exit(1);
* Look up connection factory and queue. If either does
* not exist, exit.
try {
queueConnectionFactory = (QueueConnectionFactory)
jndiContext.lookup("QueueConnectionFactory");
queue = (Queue) jndiContext.lookup(queueName);
} catch (NamingException e) {
System.out.println("JNDI API lookup failed: " +
e.toString());
System.exit(1);
* Create connection.
* Create session from connection; false means session is
* not transacted.
* Create sender and text message.
* Send messages, varying text slightly.
* Send end-of-messages message.
* Finally, close connection.
System.out.println("nakarating dito");
try {
queueConnection =
queueConnectionFactory.createQueueConnection();
queueSession =
queueConnection.createQueueSession(false,
Session.AUTO_ACKNOWLEDGE);
queueSender = queueSession.createSender(queue);
message = queueSession.createTextMessage();
System.out.println("queueSender:" + queueSender);
System.out.println("queueSession" + queueSession);
System.out.println("message:" + message);
System.out.println("queue:" + queue);
for (int i = 0; i < NUM_MSGS; i++) {
                    TextMessage mymessage = queueSession.createTextMessage();
                    System.out.println("mymessage:" + mymessage);
                    mymessage.setText("Test lang po"); // msg_text is a String
                    queueSender.send(mymessage);
// message.setText("This is message " + (i + 1));
System.out.println("Sending message: " );
// + message.getText());
// queueSender.send(message);
* Send a non-text control message indicating end of
* messages.
//queueSender.send(queueSession.createMessage());
} catch (JMSException e) {
System.out.println("Exception occurred: " +
e.toString());
} finally {
if (queueConnection != null) {
try {
queueConnection.close();
} catch (JMSException e) {}
I am using j2ee 1.3.xx jms provider. In which by default has that MyQueueStarting JMS service...
So all of the administered objects are fine except that queueSession.CreateMessage() always yields a null object.
I have paste my j2ee console message on startup.
Thanks.
Initialization complete - waiting for client requests
Binding: < JMS Destination : jms/Topic , javax.jms.Topic >
Binding: < JMS Destination : MyQueue , javax.jms.Queue >
Binding: < JMS Destination : jms/Queue , javax.jms.Queue >
Binding: < JMS Cnx Factory : jms/QueueConnectionFactory , Queue , No properties
>
Binding: < JMS Cnx Factory : jms/TopicConnectionFactory , Topic , No properties
>
Binding: < JMS Cnx Factory : TopicConnectionFactory , Topic , No properties >
Binding: < JMS Cnx Factory : QueueConnectionFactory , Queue , No properties >
Starting web service at port: 8000