AMQ-2029 set JMS* headers on non-amq messages, with a test

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@725019 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
David Jencks 2008-12-10 07:14:21 +00:00
parent 05602bb0b1
commit 9e6f62b7c2
2 changed files with 32 additions and 14 deletions

View File

@ -1603,6 +1603,21 @@ public class ActiveMQSession implements Session, QueueSession, TopicSession, Sta
TransactionId txid = transactionContext.getTransactionId();
long sequenceNumber = producer.getMessageSequence();
//Set the "JMS" header fields on the orriginal message, see 1.1 spec section 3.4.11
message.setJMSDestination(destination);
message.setJMSDeliveryMode(deliveryMode);
long expiration = 0L;
if (!producer.getDisableMessageTimestamp()) {
long timeStamp = System.currentTimeMillis();
message.setJMSTimestamp(timeStamp);
if (timeToLive > 0) {
expiration = timeToLive + timeStamp;
}
}
message.setJMSExpiration(expiration);
message.setJMSPriority(priority);
message.setJMSRedelivered(false);
// transform to our own message format here
ActiveMQMessage msg = ActiveMQMessageTransformation.transformMessage(message, connection);
@ -1616,19 +1631,6 @@ public class ActiveMQSession implements Session, QueueSession, TopicSession, Sta
//clear the brokerPath in case we are re-sending this message
msg.setBrokerPath(null);
msg.setJMSDestination(destination);
msg.setJMSDeliveryMode(deliveryMode);
long expiration = 0L;
if (!producer.getDisableMessageTimestamp()) {
long timeStamp = System.currentTimeMillis();
msg.setJMSTimestamp(timeStamp);
if (timeToLive > 0) {
expiration = timeToLive + timeStamp;
}
}
msg.setJMSExpiration(expiration);
msg.setJMSPriority(priority);
msg.setJMSRedelivered(false);
msg.setTransactionId(txid);
if (connection.isCopyMessageOnSend()) {

View File

@ -465,7 +465,23 @@ public class JMSMessageTest extends JmsTestSupport {
ForeignMessage message = new ForeignMessage();
message.text = "Hello";
message.setStringProperty("test", "value");
producer.send(message);
long timeToLive = 10000L;
long start = System.currentTimeMillis();
producer.send(message, Session.AUTO_ACKNOWLEDGE, 7, timeToLive);
long end = System.currentTimeMillis();
//validate jms spec 1.1 section 3.4.11 table 3.1
// JMSDestination, JMSDeliveryMode, JMSExpiration, JMSPriority, JMSMessageID, and JMSTimestamp
//must be set by sending a message.
assertEquals(destination, message.getJMSDestination());
assertEquals(Session.AUTO_ACKNOWLEDGE, message.getJMSDeliveryMode());
assertTrue(start + timeToLive <= message.getJMSExpiration());
assertTrue(end + timeToLive >= message.getJMSExpiration());
assertEquals(7, message.getJMSPriority());
assertNotNull(message.getJMSMessageID());
assertTrue(start <= message.getJMSTimestamp());
assertTrue(end >= message.getJMSTimestamp());
}
// Validate message is OK.