import javax.jms.*;
import javax.naming.InitialContext;
import java.util.Enumeration;
import java.util.Scanner;
public class TesteQueueBrowser {
public static void main(String[] args) throws Exception{
InitialContext context = new InitialContext();
//imports do package javax.jms
// Pega a conexão do contexto: lookup
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");
QueueBrowser browser = session.createBrowser((Queue) fila);
//Podemos usar o método getEnumeration que retorna uma estrutura contendo as mensagens:
Enumeration msgs = browser.getEnumeration();
while (msgs.hasMoreElements()) {
TextMessage msg = (TextMessage) msgs.nextElement();
System.out.println("Message: " + msg.getText());
}
new Scanner(System.in).nextLine(); //parar o programa para testar a conexao
session.close();
connection.close();
context.close();
}
}