Java Code Examples for javax.jms.Message#propertyExists()

The following examples show how to use javax.jms.Message#propertyExists() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MaxDeliveryTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
private void browseQueueAndValidationDeliveryHeaders(final Session session, final Queue queue) throws Exception
{
    final QueueBrowser browser = session.createBrowser(queue);
    @SuppressWarnings("unchecked")
    final List<Message> messages = (List<Message>) new ArrayList(Collections.list(browser.getEnumeration()));
    assertThat("Unexpected number of messages seen by browser", messages.size(), is(equalTo(1)));
    final Message browsedMessage = messages.get(0);
    assertThat(browsedMessage.getJMSRedelivered(), is(equalTo(false)));

    if (browsedMessage.propertyExists(JMSX_DELIVERY_COUNT))
    {
        assertThat(browsedMessage.getIntProperty(JMSX_DELIVERY_COUNT), is(equalTo(1)));

    }
    browser.close();
}
 
Example 2
Source File: JMSMessageHeadersType.java    From cxf with Apache License 2.0 6 votes vote down vote up
private void read(Message message) throws JMSException {
    setJMSCorrelationID(message.getJMSCorrelationID());
    setJMSDeliveryMode(Integer.valueOf(message.getJMSDeliveryMode()));
    setJMSExpiration(Long.valueOf(message.getJMSExpiration()));
    setJMSMessageID(message.getJMSMessageID());
    setJMSPriority(Integer.valueOf(message.getJMSPriority()));
    setJMSRedelivered(Boolean.valueOf(message.getJMSRedelivered()));
    setJMSTimeStamp(Long.valueOf(message.getJMSTimestamp()));
    setJMSType(message.getJMSType());
    setSOAPJMSTargetService(message.getStringProperty(JMSSpecConstants.TARGETSERVICE_FIELD));
    setSOAPJMSBindingVersion(message.getStringProperty(JMSSpecConstants.BINDINGVERSION_FIELD));
    setSOAPJMSContentType(message.getStringProperty(JMSSpecConstants.CONTENTTYPE_FIELD));
    setSOAPJMSContentEncoding(message.getStringProperty(JMSSpecConstants.CONTENTENCODING_FIELD));
    setSOAPJMSSOAPAction(message.getStringProperty(JMSSpecConstants.SOAPACTION_FIELD));
    if (message.propertyExists(JMSSpecConstants.ISFAULT_FIELD)) {
        setSOAPJMSIsFault(message.getBooleanProperty(JMSSpecConstants.ISFAULT_FIELD));
    }
    setSOAPJMSRequestURI(message.getStringProperty(JMSSpecConstants.REQUESTURI_FIELD));

    setJMSReplyTo(getDestName(message));
    readProperties(message);
}
 
Example 3
Source File: RetryCapableMDB.java    From hawkular-apm with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessage(Message message) {
    if (log.isLoggable(Level.FINEST)) {
        log.finest("Message received=" + message);
    }

    try {
        String tenantId = message.getStringProperty("tenant");

        int retryCount;

        if (message.propertyExists("retryCount")) {
            retryCount = message.getIntProperty("retryCount");
        } else {
            retryCount = maxRetryCount;
        }

        String data = ((TextMessage) message).getText();

        List<S> items = mapper.readValue(data, getTypeReference());

        process(tenantId, items, retryCount);

    } catch (Exception e) {
        if (processor.isReportRetryExpirationAsWarning()) {
            serverMsgLogger.warnMaxRetryReached(e);
        } else if (log.isLoggable(Level.FINEST)) {
            log.log(Level.FINEST, "Maximum retry reached. Last exception to occur ....", e);
        }
    }
}
 
Example 4
Source File: RequestReplyToTopicViaThreeNetworkHopsTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected void checkMessage(Message in_msg) throws Exception {
   int seq;

   LOG.debug("received message " + fmtMsgInfo(in_msg) + " from " + in_msg.getJMSDestination());

   //
   // Only check messages with a sequence number.
   //

   if (in_msg.propertyExists("SEQ")) {
      seq = in_msg.getIntProperty("SEQ");

      if ((haveFirstSeq) && (seq != (lastSeq + 1))) {
         LOG.error("***ERROR*** incorrect sequence number; expected " + Integer.toString(lastSeq + 1) + " but have " + Integer.toString(seq));

         testError = true;
      }

      lastSeq = seq;

      if (msgCount > expectedCount) {
         LOG.error("*** have more messages than expected; have " + msgCount + "; expect " + expectedCount);

         testError = true;
      }
   }

   if (in_msg.propertyExists("end-of-response")) {
      LOG.trace("received end-of-response message");
   }
}
 
Example 5
Source File: MessageGroupCloseTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void checkMessage(Message m,
                         String consumerId,
                         Map<String, Integer> messageGroups,
                         Set<String> closedGroups) throws JMSException {
   String groupId = m.getStringProperty("JMSXGroupID");
   int seq = m.getIntProperty("JMSXGroupSeq");
   Integer count = messageGroups.get(groupId);
   if (count == null) {
      // first time seeing this group
      if (!m.propertyExists("JMSXGroupFirstForConsumer") || !m.getBooleanProperty("JMSXGroupFirstForConsumer")) {
         LOG.info(consumerId + ": JMSXGroupFirstForConsumer not set for group=" + groupId + ", seq=" + seq);
         errorCountFirstForConsumer++;
      }
      if (seq == -1) {
         closedGroups.add(groupId);
         LOG.info(consumerId + ": wrong consumer got close message for group=" + groupId);
         errorCountWrongConsumerClose++;
      }
      messageGroups.put(groupId, 1);
   } else {
      // existing group
      if (closedGroups.contains(groupId)) {
         // group reassigned to same consumer
         closedGroups.remove(groupId);
         if (!m.propertyExists("JMSXGroupFirstForConsumer") || !m.getBooleanProperty("JMSXGroupFirstForConsumer")) {
            LOG.info(consumerId + ": JMSXGroupFirstForConsumer not set for group=" + groupId + ", seq=" + seq);
            errorCountFirstForConsumer++;
         }
         if (seq == -1) {
            LOG.info(consumerId + ": consumer got duplicate close message for group=" + groupId);
            errorCountDuplicateClose++;
         }
      }
      if (seq == -1) {
         closedGroups.add(groupId);
      }
      messageGroups.put(groupId, count + 1);
   }
}
 
Example 6
Source File: ActiveMQClientHeader.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
public final T getMessage(Message message, ActiveMQClientHeader key, T defaultValue) {
    String id = key.id;
    try {
        if (message.propertyExists(id)) {
            return getMessage0(message, id);
        }
    } catch (JMSException e) {
        // just ignore and return default value
    }
    return defaultValue;
}
 
Example 7
Source File: LastValueQueueTest.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
private Map<String, Integer> receiveMessages(BackgroundMessageProducer producer, final Queue queue) throws Exception
{
    producer.waitUntilQuarterOfMessagesSentToEncourageConflation();

    Map<String, Integer> messageSequenceNumbersByKey = new HashMap<>();
    Connection consumerConnection = getConnectionBuilder().setPrefetch(1).build();
    try
    {

        Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        LOGGER.info("Starting to receive");

        MessageConsumer consumer = consumerSession.createConsumer(queue);
        consumerConnection.start();

        Message message;
        int numberOfShutdownsReceived = 0;
        int numberOfMessagesReceived = 0;
        while (numberOfShutdownsReceived < 2)
        {
            message = consumer.receive(getReceiveTimeout());
            assertNotNull("null received after "
                          + numberOfMessagesReceived
                          + " messages and "
                          + numberOfShutdownsReceived
                          + " shutdowns", message);

            if (message.propertyExists(BackgroundMessageProducer.SHUTDOWN))
            {
                numberOfShutdownsReceived++;
            }
            else
            {
                numberOfMessagesReceived++;
                putMessageInMap(message, messageSequenceNumbersByKey);
            }
        }

        LOGGER.info("Finished receiving.  Received " + numberOfMessagesReceived + " message(s) in total");
    }
    finally
    {
        consumerConnection.close();
    }
    return messageSequenceNumbersByKey;
}
 
Example 8
Source File: DurableSubProcessTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
private void process(long millis) throws JMSException {
   long end = System.currentTimeMillis() + millis;
   long hardEnd = end + 2000; // wait to finish the transaction.
   boolean inTransaction = false;
   int transCount = 0;

   LOG.info(toString() + " ONLINE.");
   Connection con = openConnection();
   Session sess = con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
   MessageConsumer consumer = sess.createDurableSubscriber(topic, SUBSCRIPTION_NAME, selector, false);
   try {
      do {
         long max = end - System.currentTimeMillis();
         if (max <= 0) {
            if (!inTransaction)
               break;

            max = hardEnd - System.currentTimeMillis();
            if (max <= 0)
               exit("" + this + " failed: Transaction is not finished.");
         }

         Message message = consumer.receive(max);
         if (message == null)
            continue;

         onClientMessage(message);

         if (message.propertyExists("COMMIT")) {
            message.acknowledge();

            LOG.info("Received Trans[id=" + message.getIntProperty("TRANS") + ", count=" + transCount + "] in " + this + ".");

            inTransaction = false;
            transCount = 0;
         } else {
            inTransaction = true;
            transCount++;
         }
      } while (true);
   } finally {
      sess.close();
      con.close();

      LOG.info(toString() + " OFFLINE.");

      // Check if the messages are in the waiting
      // list for long time.
      Message topMessage = waitingList.peek();
      if (topMessage != null)
         checkDeliveryTime(topMessage);
   }
}
 
Example 9
Source File: DurableSubProcessWithRestartTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
private void process(long millis) throws JMSException {
   long end = System.currentTimeMillis() + millis;
   long hardEnd = end + 20000; // wait to finish the transaction.
   boolean inTransaction = false;
   int transCount = 0;

   LOG.info(toString() + " ONLINE.");
   Connection con = openConnection();
   Session sess = con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
   MessageConsumer consumer = sess.createDurableSubscriber(topic, SUBSCRIPTION_NAME, selector, false);
   try {
      do {
         long max = end - System.currentTimeMillis();
         if (max <= 0) {
            if (!inTransaction)
               break;

            max = hardEnd - System.currentTimeMillis();
            if (max <= 0)
               exit("" + this + " failed: Transaction is not finished.");
         }

         Message message = consumer.receive(max);
         if (message == null)
            continue;

         onClientMessage(message);

         if (message.propertyExists("COMMIT")) {
            message.acknowledge(); // CLIENT_ACKNOWLEDGE

            LOG.info("Received Trans[id=" + message.getIntProperty("TRANS") + ", count=" + transCount + "] in " + this + ".");

            inTransaction = false;
            transCount = 0;
         } else {
            inTransaction = true;
            transCount++;
         }
      } while (true);
   } finally {
      sess.close();
      con.close();

      LOG.info(toString() + " OFFLINE.");

      // Check if the messages are in the waiting
      // list for long time.
      Message topMessage = waitingList.peek();
      if (topMessage != null)
         checkDeliveryTime(topMessage);
   }
}
 
Example 10
Source File: DurableSubDelayedUnsubscribeTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
private void process(long processingTime) throws JMSException {
   long end = System.currentTimeMillis() + processingTime;
   long hardEnd = end + 20000; // wait to finish the transaction.
   boolean inTransaction = false;
   int transCount = 0;

   LOG.info(toString() + " ONLINE.");
   Connection con = openConnection();
   Session sess = con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
   MessageConsumer consumer = sess.createDurableSubscriber(topic, SUBSCRIPTION_NAME, selector, false);
   try {
      do {
         long max = end - System.currentTimeMillis();
         if (max <= 0) {
            if (!inTransaction)
               break;

            max = hardEnd - System.currentTimeMillis();
            if (max <= 0)
               exit("" + this + " failed: Transaction is not finished.");
         }

         Message message = consumer.receive(max);
         if (message == null)
            continue;

         if (message.propertyExists("COMMIT")) {
            message.acknowledge(); // CLIENT_ACKNOWLEDGE

            LOG.info("Received Trans[id=" + message.getIntProperty("TRANS") + ", count=" + transCount + "] in " + this + ".");

            inTransaction = false;
            transCount = 0;
         } else {
            inTransaction = true;
            transCount++;
         }
      } while (true);
   } finally {
      sess.close();
      con.close();
      LOG.info(toString() + " OFFLINE.");
   }
}
 
Example 11
Source File: DurableSubProcessConcurrentCommitActivateNoDuplicateTest.java    From activemq-artemis with Apache License 2.0 4 votes vote down vote up
private void process(long millis) throws JMSException {
   //long end = System.currentTimeMillis() + millis;
   long end = System.currentTimeMillis() + 200;
   long hardEnd = end + 20000; // wait to finish the transaction.
   boolean inTransaction = false;
   int transCount = 0;

   Connection con = openConnection();
   Session sess = con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
   consumer = (ActiveMQMessageConsumer) sess.createDurableSubscriber(topic, SUBSCRIPTION_NAME, selector, false);
   LOG.info(toString() + " ONLINE.");
   try {
      do {
         long max = end - System.currentTimeMillis();
         if (max <= 0) {
            if (!inTransaction) {
               LOG.info(toString() + " done after no work!");
               break;
            }

            max = hardEnd - System.currentTimeMillis();
            if (max <= 0)
               exit("" + this + " failed: Transaction is not finished.");
         }

         Message message = consumer.receive(max);
         if (message == null)
            continue;

         onClientMessage(message);

         if (message.propertyExists("COMMIT")) {
            message.acknowledge(); // CLIENT_ACKNOWLEDGE

            int trans = message.getIntProperty("TRANS");
            LOG.info("Received Trans[id=" + trans + ", count=" + transCount + "] in " + this + ".");

            inTransaction = false;
            transCount = 0;

            int committing = server.committingTransaction;
            if (committing == trans) {
               LOG.info("Going offline during transaction commit. messageID=" + message.getIntProperty("ID"));
               break;
            }
         } else {
            inTransaction = true;
            transCount++;
            if (1 == transCount) {
               LOG.info("In Trans[id=" + message.getIntProperty("TRANS") + "] first ID=" + message.getIntProperty("ID"));
            }
         }
      } while (true);
   } finally {
      sess.close();
      con.close();

      LOG.info(toString() + " OFFLINE.");

      // Check if the messages are in the waiting
      // list for long time.
      Message topMessage = waitingList.peek();
      if (topMessage != null)
         checkDeliveryTime(topMessage);
   }
}