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

The following examples show how to use javax.jms.Message#setJMSMessageID() . 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: SelectorTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void testJMSPropertySelectors() throws Exception {
   Message message = createMessage();
   message.setJMSType("selector-test");
   message.setJMSMessageID("id:test:1:1:1:1");

   assertSelector(message, "JMSType = 'selector-test'", true);
   assertSelector(message, "JMSType = 'crap'", false);

   assertSelector(message, "JMSMessageID = 'id:test:1:1:1:1'", true);
   assertSelector(message, "JMSMessageID = 'id:not-test:1:1:1:1'", false);

   message = createMessage();
   message.setJMSType("1001");

   assertSelector(message, "JMSType='1001'", true);
   assertSelector(message, "JMSType='1001' OR JMSType='1002'", true);
   assertSelector(message, "JMSType = 'crap'", false);
}
 
Example 2
Source File: SelectorTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected Message createMessage() throws JMSException {
   Message message = createMessage("FOO.BAR");
   message.setJMSType("selector-test");
   message.setJMSMessageID("connection:1:1:1:1");
   message.setObjectProperty("name", "James");
   message.setObjectProperty("location", "London");

   message.setByteProperty("byteProp", (byte) 123);
   message.setByteProperty("byteProp2", (byte) 33);
   message.setShortProperty("shortProp", (short) 123);
   message.setIntProperty("intProp", 123);
   message.setLongProperty("longProp", 123);
   message.setFloatProperty("floatProp", 123);
   message.setDoubleProperty("doubleProp", 123);

   message.setIntProperty("rank", 123);
   message.setIntProperty("version", 2);
   message.setStringProperty("quote", "'In God We Trust'");
   message.setStringProperty("foo", "_foo");
   message.setStringProperty("punctuation", "!#$&()*+,-./:;<=>?@[\\]^`{|}~");
   message.setBooleanProperty("trueProp", true);
   message.setBooleanProperty("falseProp", false);
   return message;
}
 
Example 3
Source File: MessageHeaderTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Test that the <code>JMSMessageID</code> header field value is
 * ignored when the message is sent.
 */
@Test
public void testJMSMessageID_1() {
   try {
      Message message = senderSession.createMessage();
      message.setJMSMessageID("ID:foo");
      sender.send(message);
      Assert.assertTrue("sec. 3.4.3 When a message is sent this value is ignored.\n", !message.getJMSMessageID().equals("ID:foo"));
      receiver.receive(TestConfig.TIMEOUT);
   } catch (JMSException e) {
      fail(e);
   }
}
 
Example 4
Source File: JMSMessageIDHeaderTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testJMSMessageIDChangedAfterSendingMessage() throws Exception {
   try {
      Message m = queueProducerSession.createMessage();
      m.setJMSMessageID("ID:something");

      queueProducer.send(m);

      ProxyAssertSupport.assertFalse("ID:something".equals(m.getJMSMessageID()));
   } finally {
      removeAllMessages(queue1.getQueueName(), true);
   }
}
 
Example 5
Source File: MockJMSSession.java    From pooled-jms with 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 6
Source File: ScheduledProducer.java    From galeb with Apache License 2.0 4 votes vote down vote up
private void defineUniqueId(final Message message, String uniqueId) throws JMSException {
    message.setStringProperty("_HQ_DUPL_ID", uniqueId);
    message.setJMSMessageID(uniqueId);
    message.setStringProperty(HDR_DUPLICATE_DETECTION_ID.toString(), uniqueId);
}
 
Example 7
Source File: MessageCreator.java    From qpid-broker-j with 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 8
Source File: ProducerIntegrationTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
private void doSendingMessageWithDisableMessageIDHintTestImpl(boolean existingId) throws JMSException, InterruptedException, Exception, IOException {
    try(TestAmqpPeer testPeer = new TestAmqpPeer();) {
        Connection connection = testFixture.establishConnecton(testPeer);
        testPeer.expectBegin();
        testPeer.expectSenderAttach();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        String queueName = "myQueue";
        Queue queue = session.createQueue(queueName);
        MessageProducer producer = session.createProducer(queue);

        String text = "myMessage";
        MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true).withDurable(equalTo(true));
        MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true);
        MessagePropertiesSectionMatcher propsMatcher = new MessagePropertiesSectionMatcher(true);
        propsMatcher.withMessageId(nullValue()); // Check there is no message-id value;
        TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher();
        messageMatcher.setHeadersMatcher(headersMatcher);
        messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher);
        messageMatcher.setPropertiesMatcher(propsMatcher);
        messageMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(text));
        testPeer.expectTransfer(messageMatcher);
        testPeer.expectClose();

        Message message = session.createTextMessage(text);

        assertNull("JMSMessageID should not yet be set", message.getJMSMessageID());

        if (existingId) {
            // [erroneously] set a JMSMessageID value
            String existingMessageId = "ID:this-should-be-overwritten-in-send";
            message.setJMSMessageID(existingMessageId);
            assertEquals("JMSMessageID should now be set", existingMessageId, message.getJMSMessageID());
        }

        producer.setDisableMessageID(true);
        producer.send(message);

        assertNull("JMSMessageID should be null", message.getJMSMessageID());

        connection.close();

        testPeer.waitForAllHandlersToComplete(2000);
    }
}