1
I’m creating a rudimentary chat for a university job, using JMS and Activemq
You’re giving me this mistake that until then I couldn’t understand which mistake is this and why
javax.jms.JMSException: Channel was inactive for too long: localhost/127.0.0.1:8161
I may be making a fool of myself, but follow the implementation of my topic and the queues.
private void topicos(){
Context context = initContext();
TopicConnectionFactory connectionFactory = null;
Topic topic = null;
try{
connectionFactory = (TopicConnectionFactory) context.lookup("ConnectionFactory");
topic = (Topic) context.lookup("Topic");
}catch(NamingException nex){
alertDialog("Impossível se conectar!" );
alertDialog("Exceção gerada: " + nex);
System.exit(-1);
}
TopicConnection connection = null; //Criando a conexão e a sessão
try{
connection = connectionFactory.createTopicConnection();
TopicSession session = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicSubscriber subscriber = session.createSubscriber(topic);
subscriber.setMessageListener(new Mensagens());
connection.start();
}catch(JMSException jex){
alertDialog("Impossível de se conectar");
System.out.println("Exceção gerada" + jex);
}
}
private void filas(){
Context context = initContext();
QueueConnectionFactory connectionFactory = null; // Cconexões da fábrica e da fila de destino
Queue queue = null;
try {
connectionFactory = (QueueConnectionFactory) context.lookup("ConnectionFactory");//pesquisa conexão
queue = (Queue) context.lookup("Queue");//pesquisa o serviço
} catch (NamingException e) {
System.exit(-1);
}
QueueConnection connection = null;
try {// Criando a conexão e da sessão
connection = connectionFactory.createQueueConnection();
//false => não utiliza transação)
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
String codigoUsuario = "KEY='" + usuario + "'";
QueueReceiver receiver = session.createReceiver(queue, codigoUsuario); //passa a fila e a "senha" - nome do usuario
receiver.setMessageListener(new Mensagens());
connection.start();
} catch (JMSException e) {
e.printStackTrace();
}
}