Example #1
0
 private void stopContext() {
   try {
     context.stop();
   } catch (Throwable t) {
     error = t;
   }
 }
 public static void main(String[] args) throws NamingException {
   final InitialContext ic = new InitialContext();
   ConnectionFactory factory = (ConnectionFactory) ic.lookup("jms/RemoteConnectionFactory");
   Queue queue = (Queue) ic.lookup("jms/FILA.GERADOR");
   try (JMSContext context = factory.createContext("jms", "jms2")) {
     JMSConsumer consumer = context.createConsumer(queue);
     consumer.setMessageListener(new TratadorDeMensagem());
     context.start();
     Scanner teclado = new Scanner(System.in);
     System.out.println("Tratador esperando as mensagens na fila JMS");
     teclado.nextLine();
     teclado.close();
     context.stop();
   }
 }