activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Molina sarah <mome...@yahoo.com>
Subject JNDI lookup of topic failure
Date Sat, 30 Jan 2016 16:44:36 GMT
I am a new user. I am running ActiveMQ server with default settings in my
windows box. I am trying to run a simple msg publisher/subscriber program.
In my publisher program, I am creating a topic and then publishing to it
without any problem.
The code sample looks like this:

        Properties initialProperties = new Properties();
        initialProperties.put(InitialContext.INITIAL_CONTEXT_FACTORY,
                "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
        initialProperties.put(InitialContext.PROVIDER_URL,
                "tcp://localhost:61616");
        try {
            context = new InitialContext(initialProperties);
            factory = (TopicConnectionFactory) context
                    .lookup("ConnectionFactory");
            
            connection = factory.createTopicConnection();
            session = connection.createTopicSession(false,
                    TopicSession.AUTO_ACKNOWLEDGE);
            Topic topic = session.createTopic("MSGQUEUE");
            publisher = session.createPublisher(topic);
            TextMessage message = session.createTextMessage();
            message.setText("Hello world from publisher");
            connection.start();
            publisher.publish(message);
            System.out.println("Message has successfully sent...");
            connection.close();
            context.close();

        } catch (NamingException e) {
            e.printStackTrace();
        } catch (JMSException e) {
            e.printStackTrace();
        }

I can see in activemq console that it created the topic MSGQUEUE.

Now I am trying to lookup my MSGQUEUE from subscriber using the following
code:

       Properties initialProperties = new Properties();
        initialProperties.put(InitialContext.INITIAL_CONTEXT_FACTORY,
                "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
        initialProperties.put(InitialContext.PROVIDER_URL,
                "tcp://localhost:61616");
        try {
            context = new InitialContext(initialProperties);
            factory = (TopicConnectionFactory) context
                    .lookup("ConnectionFactory");
            connection = factory.createTopicConnection();
            session = connection.createTopicSession(false,
                    TopicSession.AUTO_ACKNOWLEDGE);
            Topic topic = (Topic) context.lookup("MSGQUEUE");
            subscriber = session.createSubscriber(topic);
            subscriber.setMessageListener(this);
            connection.start();
            ...
            ...

It fails with the NamingExcention as below:
javax.naming.NameNotFoundException: MSGQUEUE
	at
org.apache.activemq.jndi.ReadOnlyContext.lookup(ReadOnlyContext.java:235)
	at javax.naming.InitialContext.lookup(InitialContext.java:417)
	at com.example.messageq.Receiver.subscribeMessage(Receiver.java:39)
	at com.example.messageq.Receiver.main(Receiver.java:77)

Instead of context.lookup, if I use session.createTopic just like publisher
code, it works fine.
What is the reason it can not see the topic? I must be misisng something
simple.
Any help would be appreciated.



--
View this message in context: http://activemq.2283324.n4.nabble.com/JNDI-lookup-of-topic-failure-tp4706684.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Mime
View raw message