コード例 #1
0
 public void sendException(QueueSession session, Queue queue, Throwable exception)
     throws JMSException {
   QueueSender sender = session.createSender(queue);
   ObjectMessage message = session.createObjectMessage(exception);
   try {
     sender.send(message);
   } finally {
     sender.close();
   }
 }
コード例 #2
0
  /**
   * Sends a message to a queue.
   *
   * @param queueName
   * @param key Optional.
   * @param obj Mandatory.
   */
  public void sendMsgToQueue(final String queueName, final String key, final Serializable obj) {
    log.debug("sendMsgToQueue(queueName, key, obj)::started");
    QueueConnection conn = null;
    QueueSession session = null;
    QueueSender sender = null;

    try {
      final String jndiName = "queue/" + queueName;
      final Context ctx = getInitialContext(null);
      final QueueConnectionFactory factory =
          (QueueConnectionFactory) ctx.lookup(CONNECTION_FACTORY);
      conn = factory.createQueueConnection();
      session = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
      final Queue queue = (Queue) ctx.lookup(jndiName);
      sender = session.createSender(queue);

      ObjectMessage message = session.createObjectMessage();
      if (key == null) {
        message.setObject((Serializable) obj);
      } else {
        message.setObjectProperty(key, obj);
      }

      sender.send(message);

    } catch (NamingException e) {
      throw new LocatorException(
          "A naming exception occured while trying to send message "
              + obj
              + " to queue "
              + queueName,
          e);
    } catch (JMSException e) {
      throw new LocatorException(
          "A JMS exception occured while trying to send message " + obj + " to queue " + queueName,
          e);
    } finally {
      log.debug("sendMsgToQueue(queueName, key, obj)::finished");
      close(sender);
      close(session);
      close(conn);
    }
  }
コード例 #3
0
ファイル: SendMailListener.java プロジェクト: phcd/TAB
 /** @param failedMailId */
 public void callBack(String failedMailId) {
   try {
     Properties props = new Properties();
     props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
     props.setProperty("java.naming.provider.url", SenderConfig.getProp("callbackUrl"));
     props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");
     InitialContext ctx = new InitialContext(props);
     QueueConnectionFactory factory = (QueueConnectionFactory) ctx.lookup("ConnectionFactory");
     QueueConnection queueConnection = factory.createQueueConnection();
     QueueSession queueSession =
         queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
     Queue queue = (Queue) ctx.lookup("queue/" + SenderConfig.getProp("callbackJNDI"));
     ObjectMessage objMsg = queueSession.createObjectMessage();
     objMsg.setObject(failedMailId);
     QueueSender queueSender = queueSession.createSender(queue);
     queueSender.send(objMsg);
     queueSession.close();
     queueConnection.close();
   } catch (Exception e) {
     log.error("sendMail/SendMailListener/Exception: [" + failedMailId + "]", e);
   }
 }