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

The following examples show how to use javax.jms.Message#setJMSPriority() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * Test that the priority set by <code>Message.setJMSPriority()</code> is ignored when a
 * message is sent and that it holds the value specified when sending the message (i.e.
 * <code>Message.DEFAULT_PRIORITY</code> in this test).
 */
@Test
public void testJMSPriority_1() {
   try {
      Message message = senderSession.createMessage();
      message.setJMSPriority(0);
      sender.send(message);
      Assert.assertTrue("sec. 3.4.9 When a message is sent this value is ignored.\n", message.getJMSPriority() != 0);
      Assert.assertEquals("sec. 3.4.9 After completion of the send it holds the value specified by the " + "method sending the message.\n", Message.DEFAULT_PRIORITY, message.getJMSPriority());

      receiver.receive(TestConfig.TIMEOUT);
   } catch (JMSException e) {
      fail(e);
   }
}
 
Example 2
Source Project: localization_nifi   File: PutJMS.java    License: Apache License 2.0 4 votes vote down vote up
private Message createMessage(final Session jmsSession, final ProcessContext context, final byte[] messageContent,
        final FlowFile flowFile, final Destination replyToQueue, final Integer priority) throws JMSException {
    final Message message;

    switch (context.getProperty(MESSAGE_TYPE).getValue()) {
        case MSG_TYPE_EMPTY: {
            message = jmsSession.createTextMessage("");
            break;
        }
        case MSG_TYPE_STREAM: {
            final StreamMessage streamMessage = jmsSession.createStreamMessage();
            streamMessage.writeBytes(messageContent);
            message = streamMessage;
            break;
        }
        case MSG_TYPE_TEXT: {
            message = jmsSession.createTextMessage(new String(messageContent, UTF8));
            break;
        }
        case MSG_TYPE_MAP: {
            message = jmsSession.createMapMessage();
            break;
        }
        case MSG_TYPE_BYTE:
        default: {
            final BytesMessage bytesMessage = jmsSession.createBytesMessage();
            bytesMessage.writeBytes(messageContent);
            message = bytesMessage;
        }
    }

    message.setJMSTimestamp(System.currentTimeMillis());

    if (replyToQueue != null) {
        message.setJMSReplyTo(replyToQueue);
    }

    if (priority != null) {
        message.setJMSPriority(priority);
    }

    if (context.getProperty(ATTRIBUTES_TO_JMS_PROPS).asBoolean()) {
        copyAttributesToJmsProps(flowFile, message);
    }

    return message;
}
 
Example 3
Source Project: pooled-jms   File: MockJMSSession.java    License: Apache License 2.0 4 votes vote down vote up
void send(MockJMSMessageProducer producer, Destination destination, Message message, int deliveryMode, int priority, long timeToLive, boolean disableMessageId, boolean disableTimestamp, long deliveryDelay, CompletionListener completionListener) throws JMSException {
    sendLock.lock();
    try {
        message.setJMSDeliveryMode(deliveryMode);
        message.setJMSPriority(priority);
        message.setJMSRedelivered(false);
        message.setJMSDestination(destination);

        long timeStamp = System.currentTimeMillis();
        boolean hasTTL = timeToLive > Message.DEFAULT_TIME_TO_LIVE;
        boolean hasDelay = deliveryDelay > Message.DEFAULT_DELIVERY_DELAY;

        if (!(message instanceof MockJMSMessage)) {
            throw new IllegalStateException("Mock JMS client cannot handle foreign messages");
        }

        if (!disableTimestamp) {
            message.setJMSTimestamp(timeStamp);
        } else {
            message.setJMSTimestamp(0);
        }

        if (hasTTL) {
            message.setJMSExpiration(timeStamp + timeToLive);
        } else {
            message.setJMSExpiration(0);
        }

        long messageSequence = producer.getNextMessageSequence();
        String messageId = null;
        if (!disableMessageId) {
            messageId = producer.getProducerId() + ":"+ messageSequence;
        }

        // Set the delivery time. Purposefully avoided doing this earlier so
        // that we use the 'outbound' JmsMessage object reference when
        // updating our own message instances, avoids using the interface
        // in case the JMS 1.1 Message API is actually being used due to
        // being on the classpath too.
        long deliveryTime = timeStamp;
        if (hasDelay) {
            deliveryTime = timeStamp + deliveryDelay;
        }

        message.setJMSDeliveryTime(deliveryTime);

        // Set the message ID
        message.setJMSMessageID(messageId);

        try {
            connection.onMessageSend(this, message);
        } catch (JMSException jmsEx) {
            // If the synchronous portion of the send fails the completion be
            // notified but might depending on the circumstances of the failures,
            // remove it from the queue and check if is is already completed
            // once we decide to add completion support to the mock
            throw jmsEx;
        }
    } finally {
        sendLock.unlock();
    }
}
 
Example 4
Source Project: qpid-broker-j   File: MessageCreator.java    License: Apache License 2.0 4 votes vote down vote up
private static void setJmsHeader(final MessageDescription messageDescription,
                                 final Message message)
        throws JMSException
{
    final HashMap<MessageDescription.MessageHeader, Serializable> header =
            messageDescription.getHeaders();

    if (header == null)
    {
        return;
    }

    for (Map.Entry<MessageDescription.MessageHeader, Serializable> entry : header.entrySet())
    {
        try
        {
            switch (entry.getKey())
            {
                case DESTINATION:
                    message.setJMSDestination((Destination) entry.getValue());
                    break;
                case DELIVERY_MODE:
                    message.setJMSDeliveryMode((Integer) entry.getValue());
                    break;
                case MESSAGE_ID:
                    message.setJMSMessageID((String) entry.getValue());
                    break;
                case TIMESTAMP:
                    message.setJMSTimestamp((Long) entry.getValue());
                    break;
                case CORRELATION_ID:
                    if (entry.getValue() instanceof byte[])
                    {
                        message.setJMSCorrelationIDAsBytes((byte[]) entry.getValue());
                    }
                    else
                    {
                        message.setJMSCorrelationID((String) entry.getValue());
                    }
                    break;
                case REPLY_TO:
                    throw new RuntimeException("The Test should not set the replyTo header."
                                               + " It should rather use the dedicated method");
                case REDELIVERED:
                    message.setJMSRedelivered((Boolean) entry.getValue());
                    break;
                case TYPE:
                    message.setJMSType((String) entry.getValue());
                    break;
                case EXPIRATION:
                    message.setJMSExpiration((Long) entry.getValue());
                    break;
                case PRIORITY:
                    message.setJMSPriority((Integer) entry.getValue());
                    break;
                default:
                    throw new RuntimeException(String.format("unexpected message header '%s'", entry.getKey()));
            }
        }
        catch (ClassCastException e)
        {
            throw new RuntimeException(String.format("Could not set message header '%s' to this value: %s",
                                                     entry.getKey(),
                                                     entry.getValue()), e);
        }
    }
}
 
Example 5
Source Project: cxf   File: JMSTestUtil.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @param testcase
 * @param session
 * @param rtd
 * @return
 * @throws JMSException
 */
public static Message buildJMSMessageFromTestCase(TestCaseType testcase, Session session,
                                                  Destination rtd) throws JMSException {
    MessagePropertiesType messageProperties = testcase.getRequestMessage();
    Message jmsMessage = null;
    String messageType = messageProperties.getMessageType();
    if ("text".equals(messageType)) {
        jmsMessage = session.createTextMessage();
        ((TextMessage)jmsMessage).setText("test");
    } else if ("byte".equals(messageType)) {
        jmsMessage = session.createBytesMessage();
    } else if ("stream".equals(messageType)) {
        jmsMessage = session.createStreamMessage();
        ((StreamMessage)jmsMessage).writeString("test");
    } else {
        jmsMessage = session.createBytesMessage();
    }

    jmsMessage.setJMSReplyTo(rtd);

    if (messageProperties.isSetDeliveryMode()) {
        jmsMessage.setJMSDeliveryMode(messageProperties.getDeliveryMode());
    }
    if (messageProperties.isSetExpiration()) {
        jmsMessage.setJMSExpiration(messageProperties.getExpiration());
    }
    if (messageProperties.isSetPriority()) {
        jmsMessage.setJMSPriority(messageProperties.getPriority());
    }
    if (messageProperties.isSetExpiration()) {
        jmsMessage.setJMSPriority(messageProperties.getExpiration());
    }
    if (messageProperties.isSetCorrelationID()) {
        jmsMessage.setJMSCorrelationID(messageProperties.getCorrelationID());
    }

    if (messageProperties.isSetTargetService()
        && !"".equals(messageProperties.getTargetService().trim())) {
        jmsMessage.setStringProperty(JMSSpecConstants.TARGETSERVICE_FIELD, messageProperties
            .getTargetService().trim());
    }

    if (messageProperties.isSetBindingVersion()
        && !"".equals(messageProperties.getBindingVersion().trim())) {
        jmsMessage.setStringProperty(JMSSpecConstants.BINDINGVERSION_FIELD, messageProperties
                                     .getBindingVersion().trim());
    }

    if (messageProperties.isSetContentType()
        && !"".equals(messageProperties.getContentType().trim())) {
        jmsMessage.setStringProperty(JMSSpecConstants.CONTENTTYPE_FIELD, messageProperties
            .getContentType().trim());
    }

    if (messageProperties.isSetSoapAction()
        && !"".equals(messageProperties.getSoapAction().trim())) {
        jmsMessage.setStringProperty(JMSSpecConstants.SOAPACTION_FIELD, messageProperties
            .getSoapAction().trim());
    }

    if (messageProperties.isSetRequestURI()
        && !"".equals(messageProperties.getRequestURI().trim())) {
        jmsMessage.setStringProperty(JMSSpecConstants.REQUESTURI_FIELD, messageProperties
            .getRequestURI().trim());
    }
    return jmsMessage;
}
 
Example 6
Source Project: nifi   File: PutJMS.java    License: Apache License 2.0 4 votes vote down vote up
private Message createMessage(final Session jmsSession, final ProcessContext context, final byte[] messageContent,
        final FlowFile flowFile, final Destination replyToQueue, final Integer priority) throws JMSException {
    final Message message;

    switch (context.getProperty(MESSAGE_TYPE).getValue()) {
        case MSG_TYPE_EMPTY: {
            message = jmsSession.createTextMessage("");
            break;
        }
        case MSG_TYPE_STREAM: {
            final StreamMessage streamMessage = jmsSession.createStreamMessage();
            streamMessage.writeBytes(messageContent);
            message = streamMessage;
            break;
        }
        case MSG_TYPE_TEXT: {
            message = jmsSession.createTextMessage(new String(messageContent, UTF8));
            break;
        }
        case MSG_TYPE_MAP: {
            message = jmsSession.createMapMessage();
            break;
        }
        case MSG_TYPE_BYTE:
        default: {
            final BytesMessage bytesMessage = jmsSession.createBytesMessage();
            bytesMessage.writeBytes(messageContent);
            message = bytesMessage;
        }
    }

    message.setJMSTimestamp(System.currentTimeMillis());

    if (replyToQueue != null) {
        message.setJMSReplyTo(replyToQueue);
    }

    if (priority != null) {
        message.setJMSPriority(priority);
    }

    if (context.getProperty(ATTRIBUTES_TO_JMS_PROPS).asBoolean()) {
        copyAttributesToJmsProps(flowFile, message);
    }

    return message;
}