Пример #1
0
 public boolean waitCompletionOnStream(final long timeWait) throws JMSException {
   checkStream();
   try {
     return message.waitOutputStreamCompletion(timeWait);
   } catch (HornetQException e) {
     throw JMSExceptionHelper.convertFromHornetQException(e);
   }
 }
Пример #2
0
  public void saveToOutputStream(final OutputStream output) throws JMSException {
    checkStream();
    if (!readOnly) {
      throw new IllegalStateException("OutputStream property is only valid on received messages");
    }

    try {
      message.saveToOutputStream(output);
    } catch (HornetQException e) {
      throw JMSExceptionHelper.convertFromHornetQException(e);
    }
  }
Пример #3
0
  public void acknowledge() throws JMSException {
    if (session != null) {
      try {
        if (individualAck) {
          message.individualAcknowledge();
        }

        session.commit();
      } catch (HornetQException e) {
        throw JMSExceptionHelper.convertFromHornetQException(e);
      }
    }
  }
  public void setMessageListener(final MessageListener listener) throws JMSException {
    this.listener = listener;

    coreListener =
        listener == null
            ? null
            : new JMSMessageListenerWrapper(session, consumer, listener, ackMode);

    try {
      consumer.setMessageHandler(coreListener);
    } catch (HornetQException e) {
      throw JMSExceptionHelper.convertFromHornetQException(e);
    }
  }
  public void close() throws JMSException {
    try {
      consumer.close();

      if (autoDeleteQueueName != null) {
        // If non durable subscriber need to delete subscription too
        session.deleteQueue(autoDeleteQueueName);
      }

      session.removeConsumer(this);
    } catch (HornetQException e) {
      throw JMSExceptionHelper.convertFromHornetQException(e);
    } finally {
      closed = true;
    }
  }
  private HornetQMessage getMessage(final long timeout, final boolean noWait) throws JMSException {
    try {
      ClientMessage message;

      if (noWait) {
        message = consumer.receiveImmediate();
      } else {
        message = consumer.receive(timeout);
      }

      HornetQMessage msg = null;

      if (message != null) {
        msg =
            HornetQMessage.createMessage(
                message,
                (ackMode == Session.CLIENT_ACKNOWLEDGE
                        | ackMode == HornetQJMSConstants.INDIVIDUAL_ACKNOWLEDGE)
                    ? session.getCoreSession()
                    : null);

        try {
          msg.doBeforeReceive();
        } catch (Throwable e) {
          HornetQJMSLogger.LOGGER.errorPreparingMessage(e);

          return null;
        }

        // We Do the ack after doBeforeRecive, as in the case of large messages, this may fail so we
        // don't want messages redelivered
        // https://issues.jboss.org/browse/JBPAPP-6110
        if (session.getAcknowledgeMode() == HornetQJMSConstants.INDIVIDUAL_ACKNOWLEDGE) {
          msg.setIndividualAcknowledge();
        } else {
          message.acknowledge();
        }
      }

      return msg;
    } catch (HornetQException e) {
      throw JMSExceptionHelper.convertFromHornetQException(e);
    }
  }
  protected JBossConnection createConnectionInternal(
      final String username, final String password, final boolean isXA, final int type)
      throws JMSException {
    if (sessionFactory == null) {
      // It doesn't matter if more than one is created due to a race
      sessionFactory =
          new ClientSessionFactoryImpl(
              connectorConfig,
              backupConnectorConfig,
              pingPeriod,
              callTimeout,
              consumerWindowSize,
              consumerMaxRate,
              producerWindowSize,
              producerMaxRate,
              blockOnAcknowledge,
              blockOnNonPersistentSend,
              blockOnPersistentSend,
              autoGroupId);
    }

    if (username != null) {
      // Since core has no connection concept, we need to create a session in order to authenticate
      // at this time

      ClientSession sess = null;

      try {
        sess = sessionFactory.createSession(username, password, false, false, false, false);
      } catch (MessagingException e) {
        throw JMSExceptionHelper.convertFromMessagingException(e);
      } finally {
        if (sess != null) {
          try {
            sess.close();
          } catch (Throwable ignore) {
          }
        }
      }
    }

    return new JBossConnection(username, password, type, clientID, dupsOKBatchSize, sessionFactory);
  }