2

I am writing a Qpid client that sends a message. The example code that I am using is :

private void runTest() throws Exception {
  Properties properties = new Properties();
  properties.load(this.getClass().getResourceAsStream("helloworld.properties")); 
  Context context = new InitialContext(properties);                              

  ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup("qpidConnectionFactory");             
  Connection connection = connectionFactory.createConnection();                  
  connection.start();                                                            

  Session session = connection.createSession(true, Session.SESSION_TRANSACTED);  
  Queue queue = (Queue) context.lookup("myqueue");                               

  MessageConsumer messageConsumer = session.createConsumer(queue);               
  MessageProducer messageProducer = session.createProducer(queue);               

  TextMessage message = session.createTextMessage("Hello world!");                
  messageProducer.send(message);
  session.commit();

  message = (TextMessage)messageConsumer.receive();                               
  session.commit();
  System.out.println(message.getText());

  connection.close();                                                             
  context.close();                                                                
}

The accompanying config is :

java.naming.factory.initial = org.apache.qpid.jndi.PropertiesFileInitialContextFactory
connectionfactory.qpidConnectionFactory = amqp://guest:guest@clientid/?brokerlist='tcp://localhost:61111'
queue.myqueue = queue1

The ERROR that I am getting is :

Exception in thread "main" javax.naming.NoInitialContextException: Cannot instantiate class: org.apache.qpid.jndi.PropertiesFileInitialContextFactory [Root exception is java.lang.ClassNotFoundException: org.apache.qpid.jndi.PropertiesFileInitialContextFactory]
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:674)
    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
    at javax.naming.InitialContext.init(InitialContext.java:244)
    at javax.naming.InitialContext.<init>(InitialContext.java:216)
    at Hello.runTest(Hello.java:19)
    at Hello.main(Hello.java:13)
Caused by: java.lang.ClassNotFoundException: org.apache.qpid.jndi.PropertiesFileInitialContextFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:348)
    at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:72)
    at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:61)
    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:672)
    ... 5 more

Looks like it is unable to initialize the context for the Properties file.

I have an ActiveMQ instance running locally on port 61111. The Properties file is indeed in my CLASSPATH. What else could I be missing here ?

  • do you have all necessary libraries correctly in your lib folder? – Stultuske May 04 '17 at 18:07
  • The only Library my IDE complained about was `java.jmx.*`. So I added them. –  May 04 '17 at 18:08
  • 1
    What Qpid JMS client are you using, this seems to be an older client and not the newest official Qpid JMS client: http://qpid.apache.org/components/jms/index.html – Tim Bish May 04 '17 at 21:23

1 Answers1

0

Try java.naming.factory.initial = org.apache.qpid.jms.jndi.JmsInitialContextFactory

a.parfenov
  • 528
  • 6
  • 16