mirror of https://github.com/apache/activemq.git
fox for: https://issues.apache.org/jira/browse/AMQ-3271 git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1094807 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
eb24079a93
commit
315b00fa14
|
@ -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);
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Reference in New Issue