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

The following examples show how to use javax.jms.Message#getJMSPriority() . 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: ClientJmsDelegate.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
public Message sendNextMessage(final CreateProducerCommand command)
{
    final String messageProviderName = command.getMessageProviderName();
    final MessageProvider messageProvider = getMessageProvider(messageProviderName);

    final Session session = _testSessions.get(command.getSessionName());
    final MessageProducer producer = _testProducers.get(command.getParticipantName());
    try
    {
        Message message = messageProvider.nextMessage(session, command);
        int deliveryMode = producer.getDeliveryMode();
        int priority = producer.getPriority();
        long ttl = producer.getTimeToLive();
        if (messageProvider.isPropertySet(MessageProvider.PRIORITY))
        {
            priority = message.getJMSPriority();
        }
        if (messageProvider.isPropertySet(MessageProvider.DELIVERY_MODE))
        {
            deliveryMode = message.getJMSDeliveryMode();
        }
        if (messageProvider.isPropertySet(MessageProvider.TTL))
        {
            ttl = message.getLongProperty(MessageProvider.TTL);
        }
        producer.send(message, deliveryMode, priority, ttl);
        return message;
    }
    catch (final JMSException jmse)
    {
        throw new DistributedTestException("Unable to create and send message with producer: " +
                        command.getParticipantName() + " on session: " + command.getSessionName(), jmse);
    }
}
 
Example 2
Source File: Client.java    From qpid-broker-j with Apache License 2.0 5 votes vote down vote up
private ClientMessage buildClientMessage(final Message message) throws JMSException
{
    String jmsMessageID = message.getJMSMessageID();
    String jmsCorrelationID = message.getJMSCorrelationID();
    byte[] jmsCorrelationIDAsBytes;
    try
    {
        jmsCorrelationIDAsBytes = message.getJMSCorrelationIDAsBytes();
    }
    catch (JMSException e)
    {
        jmsCorrelationIDAsBytes = null;
    }
    long jmsTimestamp = message.getJMSTimestamp();
    int jmsDeliveryMode = message.getJMSDeliveryMode();
    boolean jmsRedelivered = message.getJMSRedelivered();
    String jmsType = message.getJMSType();
    long jmsExpiration = message.getJMSExpiration();
    int jmsPriority = message.getJMSPriority();

    return new JMSMessageAdaptor(jmsMessageID,
                                 jmsTimestamp,
                                 jmsCorrelationID,
                                 jmsCorrelationIDAsBytes,
                                 jmsDeliveryMode,
                                 jmsRedelivered,
                                 jmsType,
                                 jmsExpiration,
                                 jmsPriority);
}
 
Example 3
Source File: ConcurrentProducerQueueConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessage(Message message) {
   final long current = System.currentTimeMillis();
   final long duration = current - mark;
   receiptAccumulator += duration;
   int priority = 0;

   try {
      priority = message.getJMSPriority();
   } catch (JMSException ignored) {
   }

   if (!messageLists.containsKey(priority)) {
      messageLists.put(priority, new MessageIdList());
   }
   messageLists.get(priority).onMessage(message);

   if (count.incrementAndGet() == 1) {
      firstReceipt = duration;
      firstReceiptLatch.countDown();
      LOG.info("First receipt in " + firstReceipt + "ms");
   } else if (count.get() % batchSize == 0) {
      LOG.info("Consumed " + count.get() + " in " + batchReceiptAccumulator + "ms" + ", priority:" + priority);
      batchReceiptAccumulator = 0;
   }

   maxReceiptTime = Math.max(maxReceiptTime, duration);
   receiptAccumulator += duration;
   batchReceiptAccumulator += duration;
   mark = current;
}
 
Example 4
Source File: ConcurrentProducerDurableConsumerTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void onMessage(Message message) {
   final long current = System.currentTimeMillis();
   final long duration = current - mark;
   receiptAccumulator += duration;
   int priority = 0;
   try {
      priority = message.getJMSPriority();
   } catch (JMSException ignored) {
   }
   if (!messageLists.containsKey(priority)) {
      MessageIdList perPriorityList = new MessageIdList();
      perPriorityList.setParent(allMessagesList);
      messageLists.put(priority, perPriorityList);
   }
   messageLists.get(priority).onMessage(message);
   if (count.incrementAndGet() == 1) {
      firstReceipt = duration;
      firstReceiptLatch.countDown();
      LOG.info("First receipt in " + firstReceipt + "ms");
   } else if (count.get() % batchSize == 0) {
      LOG.info("Consumed " + count.get() + " in " + batchReceiptAccumulator + "ms" + ", priority:" + priority);
      batchReceiptAccumulator = 0;
   }
   maxReceiptTime = Math.max(maxReceiptTime, duration);
   receiptAccumulator += duration;
   batchReceiptAccumulator += duration;
   mark = current;
}
 
Example 5
Source File: MessageVerifier.java    From qpid-broker-j with Apache License 2.0 4 votes vote down vote up
private static void verifyMessageHeaders(final MessageDescription messageDescription,
                                         final Message message) throws VerificationException
{
    try
    {
        for (Map.Entry<MessageDescription.MessageHeader, Serializable> entry : messageDescription.getHeaders()
                                                                                                 .entrySet())
        {
            Object actualValue;

            switch (entry.getKey())
            {
                case DESTINATION:
                    actualValue = message.getJMSDestination();
                    break;
                case DELIVERY_MODE:
                    actualValue = message.getJMSDeliveryMode();
                    break;
                case MESSAGE_ID:
                    actualValue = message.getJMSMessageID();
                    break;
                case TIMESTAMP:
                    actualValue = message.getJMSTimestamp();
                    break;
                case CORRELATION_ID:
                    if (entry.getValue() instanceof byte[])
                    {
                        actualValue = message.getJMSCorrelationIDAsBytes();
                    }
                    else
                    {
                        actualValue = message.getJMSCorrelationID();
                    }
                    break;
                case REPLY_TO:
                    actualValue = message.getJMSReplyTo();
                    break;
                case REDELIVERED:
                    actualValue = message.getJMSRedelivered();
                    break;
                case TYPE:
                    actualValue = message.getJMSType();
                    break;
                case EXPIRATION:
                    actualValue = message.getJMSExpiration();
                    break;
                case PRIORITY:
                    actualValue = message.getJMSPriority();
                    break;
                default:
                    throw new RuntimeException(String.format("unexpected message header '%s'", entry.getKey()));
            }

            verifyEquals(String.format("Unexpected message header '%s'", entry.getKey()),
                         entry.getValue(),
                         actualValue);
        }
    }
    catch (JMSException e)
    {
        throw new RuntimeException("Unexpected exception during message header verification", e);
    }
}
 
Example 6
Source File: MessageDumpWriter.java    From a with Apache License 2.0 4 votes vote down vote up
public MessageDump toDumpMessage(Message msg) throws JMSException{
	
	MessageDump dump = new MessageDump();
	dump.JMSCorrelationID = msg.getJMSCorrelationID();
	dump.JMSMessageID = msg.getJMSMessageID();
	dump.JMSType = msg.getJMSType();
	dump.JMSDeliveryMode =  msg.getJMSDeliveryMode();
	dump.JMSExpiration = msg.getJMSExpiration();
	dump.JMSRedelivered = msg.getJMSRedelivered();
	dump.JMSTimestamp =  msg.getJMSTimestamp();
	dump.JMSPriority = msg.getJMSPriority();
	
	@SuppressWarnings("rawtypes")
	Enumeration propertyNames = msg.getPropertyNames();
	while(propertyNames.hasMoreElements()){
		String property = (String) propertyNames.nextElement();
		Object propertyValue = msg.getObjectProperty(property);
		if( propertyValue instanceof String){
			dump.stringProperties.put(property, (String)propertyValue);
		} else if ( propertyValue instanceof Integer ){
			dump.intProperties.put(property, (Integer)propertyValue);
		} else if ( propertyValue instanceof Long) {
			dump.longProperties.put(property, (Long)propertyValue);
		} else if( propertyValue instanceof Double) {
			dump.doubleProperties.put(property, (Double) propertyValue);
		} else if (propertyValue instanceof Short) {
			dump.shortProperties.put(property, (Short)propertyValue);
		} else if (propertyValue instanceof Float) {
			dump.floatProperties.put(property, (Float) propertyValue);
		} else if (propertyValue instanceof Byte) {
			dump.byteProperties.put(property, (Byte)propertyValue);
		} else if (propertyValue instanceof Boolean) {
			dump.boolProperties.put(property, (Boolean)propertyValue);
		} else if (propertyValue instanceof Serializable){
			// Object property.. if it's on Classpath and Serializable
			byte[] propBytes = SerializationUtils.serialize((Serializable) propertyValue);
			dump.objectProperties.put(property, Base64.encodeBase64String(propBytes));
		} else {
			// Corner case.
			throw new IllegalArgumentException("Property of key '"+ property +"' is not serializable. Type is: " + propertyValue.getClass().getCanonicalName());
		}
	}
	
	dump.body = "";
	dump.type = "";
	
	if (msg instanceof TextMessage) {
		dump.body = ((TextMessage)msg).getText();
		dump.type = "TextMessage";
	} else if (msg instanceof BytesMessage) {
		BytesMessage bm = (BytesMessage)msg;
		byte[] bytes = new byte[(int) bm.getBodyLength()];
		bm.readBytes(bytes);
		dump.body = Base64.encodeBase64String(bytes);
		dump.type = "BytesMessage";
	} else if (msg instanceof ObjectMessage) {
		ObjectMessage om = (ObjectMessage)msg;
		byte[] objectBytes = SerializationUtils.serialize(om.getObject());
		dump.body = Base64.encodeBase64String(objectBytes);
		dump.type = "ObjectMessage";
	}
	return dump;
}