/** Destroy the registered JMS Sessions and associated MessageConsumers. */
 @Override
 protected void doShutdown() throws JMSException {
   logger.debug("Closing JMS MessageConsumers");
   for (MessageConsumer consumer : this.consumers) {
     JmsUtils.closeMessageConsumer(consumer);
   }
   logger.debug("Closing JMS Sessions");
   for (Session session : this.sessions) {
     JmsUtils.closeSession(session);
   }
 }
  /** @return */
  public Nombre recibir() {
    MapMessage mapMessage = (MapMessage) jmsTemplate.receive("spitter.queue");

    Nombre n = new Nombre();
    try {
      n.setApellido(mapMessage.getString("lastName"));
      n.setName(mapMessage.getString("name"));
    } catch (JMSException e) {
      throw JmsUtils.convertJmsAccessException(e);
    }
    return n;
  }
Esempio n. 3
0
  /**
   * Pre tests the connection before starting the listening.
   *
   * <p>In case of connection failure the exception is thrown which prevents Camel from starting.
   *
   * @throws FailedToCreateConsumerException is thrown if testing the connection failed
   */
  protected void testConnectionOnStartup() throws FailedToCreateConsumerException {
    try {
      log.debug("Testing JMS Connection on startup for destination: {}", getDestinationName());
      Connection con = listenerContainer.getConnectionFactory().createConnection();
      JmsUtils.closeConnection(con);

      log.info(
          "Successfully tested JMS Connection on startup for destination: " + getDestinationName());
    } catch (Exception e) {
      String msg = "Cannot get JMS Connection on startup for destination " + getDestinationName();
      throw new FailedToCreateConsumerException(getEndpoint(), msg, e);
    }
  }
 /**
  * Overrides the superclass method to use the JMS 1.0.2 API to send a response.
  *
  * <p>Uses the JMS pub-sub API if the given destination is a topic, else uses the JMS queue API.
  */
 protected void sendResponse(Session session, Destination destination, Message response)
     throws JMSException {
   MessageProducer producer = null;
   try {
     if (destination instanceof Topic) {
       producer = ((TopicSession) session).createPublisher((Topic) destination);
       postProcessProducer(producer, response);
       ((TopicPublisher) producer).publish(response);
     } else {
       producer = ((QueueSession) session).createSender((Queue) destination);
       postProcessProducer(producer, response);
       ((QueueSender) producer).send(response);
     }
   } finally {
     JmsUtils.closeMessageProducer(producer);
   }
 }
  @Override
  public void onMessage(Message message) {
    ObjectMessage mapMessage = (ObjectMessage) message;

    try {
      FileDownloaded downloadCompleted = (FileDownloaded) mapMessage.getObject();
      String msg =
          String.format(
              "[%s] Completed %s \n download url: %s",
              downloadCompleted.getTime().toString(),
              downloadCompleted.getUrl(),
              downloadCompleted.getDownloadUrl());
      chatManager.sendMessage(downloadCompleted.getFrom(), msg);
    } catch (JMSException e) {
      throw JmsUtils.convertJmsAccessException(e);
    }
  }