Esempio n. 1
0
 public final NevadoMessage receiveMessage(
     NevadoConnection connection, NevadoDestination destination, long timeoutMs)
     throws JMSException, InterruptedException {
   long startTimeMs = new Date().getTime();
   SQSQueue sqsQueue = getSQSQueue(destination);
   SQSMessage sqsMessage =
       receiveSQSMessage(connection, destination, timeoutMs, startTimeMs, sqsQueue);
   if (sqsMessage != null) {
     _log.info("Received message " + sqsMessage.getMessageId());
   }
   return sqsMessage != null ? convertSqsMessage(destination, sqsMessage, false) : null;
 }
Esempio n. 2
0
  protected final NevadoMessage convertSqsMessage(
      NevadoDestination destination, SQSMessage sqsMessage, boolean readOnly) throws JMSException {
    // Get the message
    NevadoMessage message;
    String messageBody;
    if (destination instanceof NevadoQueue) {
      messageBody = sqsMessage.getMessageBody();
    } else {
      try {
        messageBody = new JSONObject(sqsMessage.getMessageBody()).getString("Message");
      } catch (JSONException e) {
        throw new JMSException(
            "Unable to parse JSON from message body: " + sqsMessage.getMessageBody());
      }
    }
    try {
      message = deserializeMessage(messageBody);
    } catch (JMSException e) {
      message = new InvalidMessage(e);
    }

    // Set the JMS Message ID
    if (message.nevadoPropertyExists(NevadoProperty.DisableMessageID)
        && (Boolean) message.getNevadoProperty(NevadoProperty.DisableMessageID)) {
      message.setJMSMessageID(null);
    } else if (message.getJMSMessageID() == null) {
      message.setJMSMessageID("ID:" + sqsMessage.getMessageId());
    }

    // Set the receipt handle and the destination
    message.setNevadoProperty(NevadoProperty.SQSReceiptHandle, sqsMessage.getReceiptHandle());
    message.setJMSDestination(destination);

    // Set if this is readonly (browsing)
    message.setReadOnly(readOnly);

    return message;
  }