From 32c1c996c018622ddc4c6191c25922ece40fb1b5 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Tue, 19 Jul 2022 13:32:14 -0400 Subject: [PATCH] Resolve Deprecations in Spring Framework 6.0 - TaskScheduler --- .../amqp/rabbit/AsyncRabbitTemplate.java | 6 +++--- .../amqp/rabbit/core/BatchingRabbitTemplate.java | 13 +++++++------ .../listener/DirectMessageListenerContainer.java | 11 ++++++----- .../listener/ContainerInitializationTests.java | 2 +- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/AsyncRabbitTemplate.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/AsyncRabbitTemplate.java index 21b08d00ec..3d31b4cd65 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/AsyncRabbitTemplate.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/AsyncRabbitTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 the original author or authors. + * Copyright 2016-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ package org.springframework.amqp.rabbit; -import java.util.Date; +import java.time.Instant; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -741,7 +741,7 @@ void startTimer() { throw new IllegalStateException("'AsyncRabbitTemplate' must be started."); } this.timeoutTask = AsyncRabbitTemplate.this.taskScheduler.schedule(new TimeoutTask(), - new Date(System.currentTimeMillis() + AsyncRabbitTemplate.this.receiveTimeout)); + Instant.now().plusMillis(AsyncRabbitTemplate.this.receiveTimeout)); } } else { diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/BatchingRabbitTemplate.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/BatchingRabbitTemplate.java index 0b19f09519..8316b3e375 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/BatchingRabbitTemplate.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/BatchingRabbitTemplate.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2019 the original author or authors. + * Copyright 2014-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import org.springframework.amqp.rabbit.batch.MessageBatch; import org.springframework.amqp.rabbit.connection.ConnectionFactory; import org.springframework.amqp.rabbit.connection.CorrelationData; +import org.springframework.lang.Nullable; import org.springframework.scheduling.TaskScheduler; /** @@ -74,12 +75,12 @@ public BatchingRabbitTemplate(ConnectionFactory connectionFactory, BatchingStrat } @Override - public synchronized void send(String exchange, String routingKey, Message message, CorrelationData correlationData) - throws AmqpException { + public synchronized void send(String exchange, String routingKey, Message message, + @Nullable CorrelationData correlationData) throws AmqpException { if (correlationData != null) { - if (logger.isDebugEnabled()) { - logger.debug("Cannot use batching with correlation data"); + if (this.logger.isDebugEnabled()) { + this.logger.debug("Cannot use batching with correlation data"); } super.send(exchange, routingKey, message, correlationData); } @@ -93,7 +94,7 @@ public synchronized void send(String exchange, String routingKey, Message messag } Date next = this.batchingStrategy.nextRelease(); if (next != null) { - this.scheduledTask = this.scheduler.schedule((Runnable) () -> releaseBatches(), next); + this.scheduledTask = this.scheduler.schedule((Runnable) () -> releaseBatches(), next.toInstant()); } } } diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainer.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainer.java index a41fec74aa..27d26326b3 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainer.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/DirectMessageListenerContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2021 the original author or authors. + * Copyright 2016-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,11 +18,12 @@ import java.io.IOException; import java.lang.reflect.Constructor; +import java.time.Duration; +import java.time.Instant; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.Date; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.LinkedList; @@ -510,7 +511,7 @@ private void startMonitor(long idleEventInterval, final Map names } } processMonitorTask(); - }, this.monitorInterval); + }, Duration.ofMillis(this.monitorInterval)); } private void checkIdle(long idleEventInterval, long now) { @@ -578,7 +579,7 @@ private boolean restartConsumer(final Map namesToQueues, List