3 Replies Latest reply on Jul 17, 2002 7:09 PM by Andreas Schaefer

    run jms test have error,please give me a hand

    tp67 Newbie

      I use default configuration on jboss3.0. I run following test program but have error.which error output: "topicFactory is null"
      pleare I shall how to do?

      test prpgram
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;

      import javax.jms.TopicConnectionFactory;
      import javax.jms.TopicConnection;
      import javax.jms.TopicSession;
      import javax.jms.TopicPublisher;
      import javax.jms.Topic;
      import javax.jms.TextMessage;
      import javax.jms.Session;
      import javax.jms.JMSException;
      import java.util.*;

      public class HelloPublisher {
      TopicConnection topicConnection;
      TopicSession topicSession;
      TopicPublisher topicPublisher;
      Topic topic;
      public HelloPublisher(String factoryJNDI, String topicJNDI) throws JMSException, NamingException {
      Hashtable props = new Hashtable();
      props.put(Context.PROVIDER_URL, "localhost:1099");
      Context context = new InitialContext(props);
      TopicConnectionFactory topicFactory =
      topicConnection = topicFactory.createTopicConnection();
      topicSession = topicConnection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
      topic = (Topic)context.lookup(topicJNDI);
      topicPublisher = topicSession.createPublisher(topic);
      public void publish(String msg) throws JMSException {
      TextMessage message = topicSession.createTextMessage();
      topicPublisher.publish(topic, message);
      public void close() throws JMSException {
      public static void main(String[] args) {
      try {
      HelloPublisher publisher = new HelloPublisher("java:/XAConnectionFactory","topic/testTopic");
      // Publish 10 messages
      for (int i = 1; i < 11; i++) {
      String msg = "Hello World no. " + i;
      System.out.println("Publishing message: " + msg);
      }catch(Exception ex) {
      System.err.println("An exception occured while testing HelloPublisher: " + ex);