How to read from messagedrivenbean/subscribe
seybaa Sep 29, 2002 4:14 AMHello forum,I really hope that some body will help,"the weblogic think there is just I am so desperated I am trying all else I only use JBOSS"
i have made a small example of MDB,and deploy it well,
then I made 2 client one to sent a message to the MDB that works well, client 2 to read from the MDB,my problem is that second client is not working, it doesn't call the MDB,when I run the secong client I get null point exception at "String msge= textMessage.getText()"I am very lost. HELP
HERE IS THE CLIENT HTAT WORKS
********************************
package mypackage1;
import javax.jms.*;
import java.util.*;
import javax.naming.*;
public class Class1
{
public static void main(String[] args) throws Exception
{
//Get the initial naming context
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, "t3://localhost:7001");
Context ctx= new InitialContext(h);
//Get the connectionfactory from the namespace
QueueConnectionFactory facory =(QueueConnectionFactory)
ctx.lookup("weblogic.jms.QueueConnectionFactory");
//create a queueConnection from the factory
QueueConnection queueConnection = facory.createQueueConnection();
//create a queueSession
QueueSession session = queueConnection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);
//get the queue
Queue queue = (Queue)ctx.lookup("logqueue");
//become a sender on the found queue in the session
QueueSender sender= session.createSender(queue);
//create and send the message
TextMessage textMessage = session.createTextMessage();
textMessage.setText("pus har got an E-mail");
sender.send(textMessage);
System.out.println("you have a another message" +textMessage);
// queueConnection.close();
session.close();
queueConnection.close();
}
}
********************************
HERE IS THE CLIENT THAT DESN'T WORK
************************************
package mypackage1;
import java.util.*;
import javax.jms.*;
import javax.naming.*;
public class Class2
{
public static void main(String[] args) throws Exception
{
//Get the initial naming context
Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, "t3://localhost:7001");
Context ctx= new InitialContext(h);
//Get the connectionfactory from the namespace
QueueConnectionFactory facory =(QueueConnectionFactory)
ctx.lookup("weblogic.jms.QueueConnectionFactory");
//create a queueConnection from the factory
QueueConnection queueConnection = facory.createQueueConnection();
//create a queueSession
QueueSession session = queueConnection.createQueueSession(true,Session.AUTO_ACKNOWLEDGE);
//get the queue
Queue queue = (Queue)ctx.lookup("logqueue");
//become a sender on the found queue in the session
QueueReceiver reciever= session.createReceiver(queue);
TextMessage textMessage= (TextMessage)reciever.receiveNoWait();
String msge= textMessage.getText();
System.out.println("you have a another message" +msge);
session.close();
queueConnection.close();
}
}
****************************************