Exception in thread "main" javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:313)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:350)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at br.com.agrotopus.jms.TesteConsumidor.main(TesteConsumidor.java:19)
```
java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
use the following property to configure the default connector
java.naming.provider.url = tcp:http://0.0.0.0:8161
use the following property to specify the JNDI name the connection factory
should appear as.
connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry
register some queues in JNDI using the form
queue.[jndiName] = [physicalName]
queue.financeiro = fila.financeiro
register some topics in JNDI using the form
topic.[jndiName] = [physicalName]
topic.MyTopic = example.MyTopic
```
package br.com.jms;
import javax.naming.InitialContext;
import java.util.Scanner;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.Session;
public class TesteConsumidor {
public static void main(String[] args) throws Exception {
InitialContext context = new InitialContext();
// imports do package javax.jms
ConnectionFactory factory = (ConnectionFactory) context.lookup("ConnectionFactory");
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination fila = (Destination) context.lookup("financeiro");
MessageConsumer consumer = session.createConsumer(fila);
Message message = consumer.receive();
System.out.println("Recebendo msg: " + message);
new Scanner(System.in).nextLine(); // parar o programa para testar a
// conexao
// fecha conexões
session.close();
connection.close();
context.close();
}
}