public void run() {
   MessageConsumer consumer = null;
   try {
     consumer =
         session.createConsumer(
             responseQueue,
             " " + TaskServiceConstants.SELECTOR_NAME + " like '" + selector + "%' ");
     ObjectMessage serverMessage = (ObjectMessage) consumer.receive();
     if (serverMessage != null) {
       ((JMSTaskClientHandler) handler)
           .messageReceived(session, readMessage(serverMessage), responseQueue, selector);
     }
   } catch (JMSException e) {
     if (!"102".equals(e.getErrorCode())) {
       throw new RuntimeException("No se pudo recibir respuesta JMS", e);
     }
     logger.info(e.getMessage());
     return;
   } catch (Exception e) {
     throw new RuntimeException("Error inesperado recibiendo respuesta JMS", e);
   } finally {
     if (consumer != null) {
       try {
         consumer.close();
       } catch (Exception e) {
         logger.info("No se pudo cerrar el consumer: " + e.getMessage());
       }
     }
   }
 }
 protected final void receiveMessages(
     JMSConsumer consumer, final int start, final int msgCount, final boolean ack) {
   try {
     for (int i = start; i < msgCount; i++) {
       Message message = consumer.receive(100);
       Assert.assertNotNull("Expecting a message " + i, message);
       final int actual = message.getIntProperty("counter");
       Assert.assertEquals("expected=" + i + ". Got: property['counter']=" + actual, i, actual);
       if (ack) message.acknowledge();
     }
   } catch (JMSException cause) {
     throw new JMSRuntimeException(cause.getMessage(), cause.getErrorCode(), cause);
   }
 }
 protected final void sendMessages(
     JMSContext context, JMSProducer producer, Queue queue, final int total) {
   try {
     for (int j = 0; j < total; j++) {
       StringBuilder sb = new StringBuilder();
       for (int m = 0; m < 200; m++) {
         sb.append(random.nextLong());
       }
       Message msg = context.createTextMessage(sb.toString());
       msg.setIntProperty("counter", j);
       producer.send(queue, msg);
     }
   } catch (JMSException cause) {
     throw new JMSRuntimeException(cause.getMessage(), cause.getErrorCode(), cause);
   }
 }
示例#4
0
  public tibjmsTopicSubscriber(String[] args) {

    parseArgs(args);

    /* print parameters */
    System.err.println(
        "\n------------------------------------------------------------------------");
    System.err.println("tibjmsTopicSubscriber SAMPLE");
    System.err.println("------------------------------------------------------------------------");
    System.err.println(
        "Server....................... " + ((serverUrl != null) ? serverUrl : "localhost"));
    System.err.println(
        "User......................... " + ((userName != null) ? userName : "******"));
    System.err.println("Topic........................ " + topicName);
    System.err.println(
        "------------------------------------------------------------------------\n");

    try {
      tibjmsUtilities.initSSLParams(serverUrl, args);
    } catch (JMSSecurityException e) {
      System.err.println(
          "JMSSecurityException: " + e.getMessage() + ", provider=" + e.getErrorCode());
      e.printStackTrace();
      System.exit(0);
    }

    if (topicName == null) {
      System.err.println("Error: must specify topic name");
      usage();
    }

    System.err.println("Subscribing to topic: " + topicName);

    try {
      TopicConnectionFactory factory = new com.tibco.tibjms.TibjmsTopicConnectionFactory(serverUrl);

      TopicConnection connection = factory.createTopicConnection(userName, password);

      TopicSession session =
          connection.createTopicSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);

      /*
       * Use createTopic() to enable subscriptions to dynamic topics.
       */
      javax.jms.Topic topic = session.createTopic(topicName);

      TopicSubscriber subscriber = session.createSubscriber(topic);

      connection.start();

      /* read topic messages */
      while (true) {
        javax.jms.Message message = subscriber.receive();
        if (message == null) break;

        System.err.println("Received message: " + message);
      }

      connection.close();
    } catch (JMSException e) {
      System.err.println("JMSException: " + e.getMessage() + ", provider=" + e.getErrorCode());
      e.printStackTrace();
      System.exit(0);
    }
  }
示例#5
0
 /**
  * Returns a map of the non-stanard information stored on the exception
  *
  * @return a map of the non-stanard information stored on the exception
  */
 public Map getInfo(Throwable t) {
   JMSException e = (JMSException) t;
   Map info = new HashMap();
   info.put("JMS Code", e.getErrorCode());
   return info;
 }
示例#6
0
 public String getMessage(Throwable t) {
   JMSException e = (JMSException) t;
   return e.getMessage() + "(JMS Code: " + e.getErrorCode() + ")";
 }