Timothy A. Bish 2011-04-18 22:56:53 +00:00
parent eb24079a93
commit 315b00fa14
2 changed files with 108 additions and 63 deletions

View File

@ -197,7 +197,7 @@ public class SchedulerBroker extends BrokerFilter implements JobListener {
Message messageSend = (Message) this.wireFormat.unmarshal(packet);
messageSend.setOriginalTransactionId(null);
Object repeatValue = messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT);
Object cronValue = messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT);
Object cronValue = messageSend.getProperty(ScheduledMessage.AMQ_SCHEDULED_CRON);
String cronStr = cronValue != null ? cronValue.toString() : null;
int repeat = 0;
if (repeatValue != null) {
@ -220,6 +220,30 @@ public class SchedulerBroker extends BrokerFilter implements JobListener {
messageSend.removeProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT);
messageSend.removeProperty(ScheduledMessage.AMQ_SCHEDULED_CRON);
if (messageSend.getTimestamp() > 0 && messageSend.getExpiration() > 0) {
long oldExpiration = messageSend.getExpiration();
long newTimeStamp = System.currentTimeMillis();
long timeToLive = 0;
long oldTimestamp = messageSend.getTimestamp();
if (oldExpiration > 0) {
timeToLive = oldExpiration - oldTimestamp;
}
long expiration = timeToLive + newTimeStamp;
if(expiration > oldExpiration) {
if (timeToLive > 0 && expiration > 0) {
messageSend.setExpiration(expiration);
}
messageSend.setTimestamp(newTimeStamp);
if (LOG.isDebugEnabled()) {
LOG.debug("Set message " + messageSend.getMessageId() + " timestamp from " + oldTimestamp + " to " + newTimeStamp);
}
}
}
final ProducerBrokerExchange producerExchange = new ProducerBrokerExchange();
producerExchange.setConnectionContext(context);
producerExchange.setMutable(true);

View File

@ -79,6 +79,27 @@ public class JmsCronSchedulerTest extends EmbeddedBrokerTestSupport {
assertEquals(COUNT, count.get());
}
public void testCronScheduleWithTtlSet() throws Exception {
Connection connection = createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumer = session.createConsumer(destination);
connection.start();
MessageProducer producer = session.createProducer(destination);
producer.setTimeToLive(TimeUnit.MINUTES.toMillis(1));
TextMessage message = session.createTextMessage("test msg ");
message.setStringProperty(ScheduledMessage.AMQ_SCHEDULED_CRON, "* * * * *");
producer.send(message);
producer.close();
Thread.sleep(TimeUnit.MINUTES.toMillis(2));
assertNotNull(consumer.receiveNoWait());
assertNull(consumer.receiveNoWait());
}
@Override
protected void setUp() throws Exception {
bindAddress = "vm://localhost";