diff --git a/spring-amqp/src/main/java/org/springframework/amqp/core/AmqpAdmin.java b/spring-amqp/src/main/java/org/springframework/amqp/core/AmqpAdmin.java index 76f7e8b6..0968cf9a 100644 --- a/spring-amqp/src/main/java/org/springframework/amqp/core/AmqpAdmin.java +++ b/spring-amqp/src/main/java/org/springframework/amqp/core/AmqpAdmin.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -17,7 +17,6 @@ package org.springframework.amqp.core; import java.util.Collections; -import java.util.Map; import java.util.Properties; import java.util.Set; @@ -130,17 +129,6 @@ public interface AmqpAdmin { @Nullable QueueInformation getQueueInfo(String queueName); - /** - * Return the manually declared AMQP objects. - * @return the manually declared AMQP objects. - * @since 2.4.13 - * @deprecated in favor of {@link #getManualDeclarableSet()}. - */ - @Deprecated - default Map getManualDeclarables() { - return Collections.emptyMap(); - } - /** * Return the manually declared AMQP objects. * @return the manually declared AMQP objects. diff --git a/spring-amqp/src/main/java/org/springframework/amqp/core/MessageProperties.java b/spring-amqp/src/main/java/org/springframework/amqp/core/MessageProperties.java index f999acc0..2aa516d7 100644 --- a/spring-amqp/src/main/java/org/springframework/amqp/core/MessageProperties.java +++ b/spring-amqp/src/main/java/org/springframework/amqp/core/MessageProperties.java @@ -356,32 +356,6 @@ public class MessageProperties implements Serializable { return this.receivedRoutingKey; } - /** - * When a delayed message exchange is used the x-delay header on a - * received message contains the delay. - * @return the received delay. - * @since 1.6 - * @deprecated in favor of {@link #getReceivedDelayLong()} - * @see #getDelay() - */ - @Deprecated(since = "3.1.2", forRemoval = true) - public Integer getReceivedDelay() { - Long receivedDelay = getReceivedDelayLong(); - return receivedDelay != null ? Math.toIntExact(receivedDelay) : null; - } - - /** - * When a delayed message exchange is used the x-delay header on a - * received message contains the delay. - * @param receivedDelay the received delay. - * @since 1.6 - * @deprecated in favor of {@link #setReceivedDelayLong(Long)} - */ - @Deprecated(since = "3.1.2", forRemoval = true) - public void setReceivedDelay(Integer receivedDelay) { - setReceivedDelayLong(receivedDelay != null ? receivedDelay.longValue() : null); - } - /** * When a delayed message exchange is used the x-delay header on a * received message contains the delay. @@ -466,30 +440,6 @@ public class MessageProperties implements Serializable { this.consumerQueue = consumerQueue; } - /** - * The x-delay header (outbound). - * @return the delay. - * @since 1.6 - * @deprecated in favor of {@link #getDelayLong()} - * @see #getReceivedDelay() - */ - @Deprecated(since = "3.1.2", forRemoval = true) - public Integer getDelay() { - Long delay = getDelayLong(); - return delay != null ? Math.toIntExact(delay) : null; - } - - /** - * Set the x-delay header. - * @param delay the delay. - * @since 1.6 - * @deprecated in favor of {@link #setDelayLong(Long)} - */ - @Deprecated(since = "3.1.2", forRemoval = true) - public void setDelay(Integer delay) { - setDelayLong(delay != null ? delay.longValue() : null); - } - /** * Get the x-delay header long value. * @return the delay. diff --git a/spring-amqp/src/main/java/org/springframework/amqp/core/QueueBuilder.java b/spring-amqp/src/main/java/org/springframework/amqp/core/QueueBuilder.java index 122a7ea1..37a622ff 100644 --- a/spring-amqp/src/main/java/org/springframework/amqp/core/QueueBuilder.java +++ b/spring-amqp/src/main/java/org/springframework/amqp/core/QueueBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2023 the original author or authors. + * Copyright 2016-2024 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. @@ -144,20 +144,6 @@ public final class QueueBuilder extends AbstractBuilder { return withArgument("x-expires", expires); } - /** - * Set the number of (ready) messages allowed in the queue before it starts to drop - * them. - * @param count the number of (ready) messages allowed. - * @return the builder. - * @since 2.2 - * @deprecated in favor of {@link #maxLength(long)}. - * @see #overflow(Overflow) - */ - @Deprecated - public QueueBuilder maxLength(int count) { - return withArgument("x-max-length", count); - } - /** * Set the number of (ready) messages allowed in the queue before it starts to drop * them. diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitAdmin.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitAdmin.java index a88392b6..b86dc806 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitAdmin.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/core/RabbitAdmin.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 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. @@ -743,24 +743,6 @@ public class RabbitAdmin implements AmqpAdmin, ApplicationContextAware, Applicat this.manualDeclarables.clear(); } - @Override - @Deprecated - public Map getManualDeclarables() { - Map declarables = new HashMap<>(); - this.manualDeclarables.forEach(declarable -> { - if (declarable instanceof Exchange exch) { - declarables.put(exch.getName(), declarable); - } - else if (declarable instanceof Queue queue) { - declarables.put(queue.getName(), declarable); - } - else if (declarable instanceof Binding) { - declarables.put(declarable.toString(), declarable); - } - }); - return declarables; - } - @Override public Set getManualDeclarableSet() { return Collections.unmodifiableSet(this.manualDeclarables); diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/BlockingQueueConsumer.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/BlockingQueueConsumer.java index 0d14eeba..dd1d6647 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/BlockingQueueConsumer.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/BlockingQueueConsumer.java @@ -874,18 +874,6 @@ public class BlockingQueueConsumer { } } - /** - * Perform a commit or message acknowledgement, as appropriate. - * NOTE: This method was never been intended tobe public. - * @param localTx Whether the channel is locally transacted. - * @return true if at least one delivery tag exists. - * @deprecated in favor of {@link #commitIfNecessary(boolean, boolean)} - */ - @Deprecated(forRemoval = true, since = "3.1.2") - public boolean commitIfNecessary(boolean localTx) { - return commitIfNecessary(localTx, false); - } - /** * Perform a commit or message acknowledgement, as appropriate. * NOTE: This method was never been intended tobe public. diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/adapter/MessagingMessageListenerAdapter.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/adapter/MessagingMessageListenerAdapter.java index a1318c69..47ffbed9 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/adapter/MessagingMessageListenerAdapter.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/adapter/MessagingMessageListenerAdapter.java @@ -28,7 +28,6 @@ import org.springframework.amqp.core.MessageProperties; import org.springframework.amqp.rabbit.listener.api.RabbitListenerErrorHandler; import org.springframework.amqp.rabbit.support.ListenerExecutionFailedException; import org.springframework.amqp.support.AmqpHeaderMapper; -import org.springframework.amqp.support.AmqpHeaders; import org.springframework.amqp.support.converter.MessageConversionException; import org.springframework.amqp.support.converter.MessageConverter; import org.springframework.amqp.support.converter.MessagingMessageConverter; @@ -41,7 +40,6 @@ import org.springframework.messaging.MessagingException; import org.springframework.messaging.handler.annotation.Header; import org.springframework.messaging.handler.annotation.Headers; import org.springframework.messaging.handler.annotation.Payload; -import org.springframework.messaging.support.MessageBuilder; import org.springframework.util.Assert; import com.rabbitmq.client.Channel; @@ -179,14 +177,7 @@ public class MessagingMessageListenerAdapter extends AbstractAdaptableMessageLis if (this.errorHandler != null) { try { - Message messageWithChannel = null; - if (message != null) { - messageWithChannel = MessageBuilder.fromMessage(message) - // TODO won't be necessary starting with version 3.2 - .setHeader(AmqpHeaders.CHANNEL, channel) - .build(); - } - Object errorResult = this.errorHandler.handleError(amqpMessage, channel, messageWithChannel, e); + Object errorResult = this.errorHandler.handleError(amqpMessage, channel, message, e); if (errorResult != null) { Object payload = message == null ? null : message.getPayload(); InvocationResult invResult = payload == null @@ -240,9 +231,9 @@ public class MessagingMessageListenerAdapter extends AbstractAdaptableMessageLis Object payload = message == null ? null : message.getPayload(); try { handleResult(new InvocationResult(new RemoteInvocationResult(throwableToReturn), null, - payload == null ? Object.class : this.handlerAdapter.getReturnTypeFor(payload), - this.handlerAdapter.getBean(), - payload == null ? null : this.handlerAdapter.getMethodFor(payload)), + payload == null ? Object.class : this.handlerAdapter.getReturnTypeFor(payload), + this.handlerAdapter.getBean(), + payload == null ? null : this.handlerAdapter.getMethodFor(payload)), amqpMessage, channel, message); } catch (ReplyFailureException rfe) { @@ -405,8 +396,8 @@ public class MessagingMessageListenerAdapter extends AbstractAdaptableMessageLis boolean isPayload = methodParameter.hasParameterAnnotation(Payload.class); if (isHeaderOrHeaders && isPayload && MessagingMessageListenerAdapter.this.logger.isWarnEnabled()) { MessagingMessageListenerAdapter.this.logger.warn(this.method.getName() - + ": Cannot annotate a parameter with both @Header and @Payload; " - + "ignored for payload conversion"); + + ": Cannot annotate a parameter with both @Header and @Payload; " + + "ignored for payload conversion"); } if (isEligibleParameter(methodParameter) // NOSONAR && (!isHeaderOrHeaders || isPayload) && !(isHeaderOrHeaders && isPayload)) { @@ -416,7 +407,7 @@ public class MessagingMessageListenerAdapter extends AbstractAdaptableMessageLis if (this.isBatch && !this.isCollection) { throw new IllegalStateException( "Mis-configuration; a batch listener must consume a List or " - + "Collection for method: " + this.method); + + "Collection for method: " + this.method); } } @@ -467,8 +458,8 @@ public class MessagingMessageListenerAdapter extends AbstractAdaptableMessageLis } else if (this.isBatch && ((parameterizedType.getRawType().equals(List.class) - || parameterizedType.getRawType().equals(Collection.class)) - && parameterizedType.getActualTypeArguments().length == 1)) { + || parameterizedType.getRawType().equals(Collection.class)) + && parameterizedType.getActualTypeArguments().length == 1)) { this.isCollection = true; Type paramType = parameterizedType.getActualTypeArguments()[0]; @@ -487,6 +478,7 @@ public class MessagingMessageListenerAdapter extends AbstractAdaptableMessageLis } return genericParameterType; } + } } diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/api/RabbitListenerErrorHandler.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/api/RabbitListenerErrorHandler.java index 3a01921f..53eb43c6 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/api/RabbitListenerErrorHandler.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/api/RabbitListenerErrorHandler.java @@ -27,28 +27,14 @@ import com.rabbitmq.client.Channel; * listener container's error handler. * * @author Gary Russell + * @author Artem Bilan + * * @since 2.0 * */ @FunctionalInterface public interface RabbitListenerErrorHandler { - /** - * Handle the error. If an exception is not thrown, the return value is returned to - * the sender using normal {@code replyTo/@SendTo} semantics. - * @param amqpMessage the raw message received. - * @param message the converted spring-messaging message (if available). - * @param exception the exception the listener threw, wrapped in a - * {@link ListenerExecutionFailedException}. - * @return the return value to be sent to the sender. - * @throws Exception an exception which may be the original or different. - * @deprecated in favor of - * {@link #handleError(Message, Channel, org.springframework.messaging.Message, ListenerExecutionFailedException)} - */ - @Deprecated(forRemoval = true, since = "3.1.3") - Object handleError(Message amqpMessage, @Nullable org.springframework.messaging.Message message, - ListenerExecutionFailedException exception) throws Exception; // NOSONAR - /** * Handle the error. If an exception is not thrown, the return value is returned to * the sender using normal {@code replyTo/@SendTo} semantics. @@ -61,12 +47,8 @@ public interface RabbitListenerErrorHandler { * @throws Exception an exception which may be the original or different. * @since 3.1.3 */ - @SuppressWarnings("deprecation") - default Object handleError(Message amqpMessage, Channel channel, + Object handleError(Message amqpMessage, Channel channel, @Nullable org.springframework.messaging.Message message, - ListenerExecutionFailedException exception) throws Exception { // NOSONAR - - return handleError(amqpMessage, message, exception); - } + ListenerExecutionFailedException exception) throws Exception; } diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/EnableRabbitIntegrationTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/EnableRabbitIntegrationTests.java index 856dc048..c59921a7 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/EnableRabbitIntegrationTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/EnableRabbitIntegrationTests.java @@ -1907,12 +1907,12 @@ public class EnableRabbitIntegrationTests extends NeedsManagementTests { @Bean public RabbitListenerErrorHandler alwaysBARHandler() { - return (msg, springMsg, ex) -> "BAR"; + return (msg, channel, springMsg, ex) -> "BAR"; } @Bean public RabbitListenerErrorHandler upcaseAndRepeatErrorHandler() { - return (msg, springMsg, ex) -> { + return (msg, channel, springMsg, ex) -> { String payload = ((Bar) springMsg.getPayload()).field.toUpperCase(); return payload + payload + " " + ex.getCause().getMessage(); }; @@ -1920,15 +1920,15 @@ public class EnableRabbitIntegrationTests extends NeedsManagementTests { @Bean public RabbitListenerErrorHandler throwANewException() { - return (msg, springMsg, ex) -> { - this.errorHandlerChannel = springMsg.getHeaders().get(AmqpHeaders.CHANNEL, Channel.class); + return (msg, channel, springMsg, ex) -> { + this.errorHandlerChannel = channel; throw new RuntimeException("from error handler", ex.getCause()); }; } @Bean public RabbitListenerErrorHandler throwWrappedValidationException() { - return (msg, springMsg, ex) -> { + return (msg, channel, springMsg, ex) -> { throw new RuntimeException("argument validation failed", ex); }; } diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/EnableRabbitReturnTypesTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/EnableRabbitReturnTypesTests.java index da80c5e2..a99fb814 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/EnableRabbitReturnTypesTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/EnableRabbitReturnTypesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2019-2020 the original author or authors. + * Copyright 2019-2024 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. @@ -143,7 +143,7 @@ public class EnableRabbitReturnTypesTests { @Bean public RabbitListenerErrorHandler rleh() { - return (amqpMessage, message, exception) -> null; + return (amqpMessage, channel, message, exception) -> null; } @RabbitListener(queues = "EnableRabbitReturnTypesTests.1", admin = "#{@admin}", diff --git a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/adapter/MessagingMessageListenerAdapterTests.java b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/adapter/MessagingMessageListenerAdapterTests.java index a268fb29..157e999a 100644 --- a/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/adapter/MessagingMessageListenerAdapterTests.java +++ b/spring-rabbit/src/test/java/org/springframework/amqp/rabbit/listener/adapter/MessagingMessageListenerAdapterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2021 the original author or authors. + * Copyright 2014-2024 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. @@ -284,17 +284,10 @@ public class MessagingMessageListenerAdapterTests { Channel channel = mock(Channel.class); AtomicBoolean ehCalled = new AtomicBoolean(); MessagingMessageListenerAdapter listener = getSimpleInstance("fail", - new RabbitListenerErrorHandler() { - - @Override - public Object handleError(org.springframework.amqp.core.Message amqpMessage, Message message, - ListenerExecutionFailedException exception) throws Exception { - - ehCalled.set(true); - return null; - } - - }, false, String.class); + (amqpMessage, channel1, message1, exception) -> { + ehCalled.set(true); + return null; + }, false, String.class); listener.setMessageConverter(new MessageConverter() { @Override @@ -319,17 +312,10 @@ public class MessagingMessageListenerAdapterTests { Channel channel = mock(Channel.class); AtomicBoolean ehCalled = new AtomicBoolean(); MessagingMessageListenerAdapter listener = getSimpleInstance("fail", - new RabbitListenerErrorHandler() { - - @Override - public Object handleError(org.springframework.amqp.core.Message amqpMessage, Message message, - ListenerExecutionFailedException exception) throws Exception { - - ehCalled.set(true); - return "foo"; - } - - }, false, String.class); + (amqpMessage, channel1, message1, exception) -> { + ehCalled.set(true); + return "foo"; + }, false, String.class); listener.setMessageConverter(new MessageConverter() { @Override diff --git a/spring-rabbit/src/test/kotlin/org/springframework/amqp/rabbit/annotation/EnableRabbitKotlinTests.kt b/spring-rabbit/src/test/kotlin/org/springframework/amqp/rabbit/annotation/EnableRabbitKotlinTests.kt index c1746759..87fe6dba 100644 --- a/spring-rabbit/src/test/kotlin/org/springframework/amqp/rabbit/annotation/EnableRabbitKotlinTests.kt +++ b/spring-rabbit/src/test/kotlin/org/springframework/amqp/rabbit/annotation/EnableRabbitKotlinTests.kt @@ -151,7 +151,7 @@ class EnableRabbitKotlinTests { val ehLatch = CountDownLatch(1) @Bean - fun eh() = RabbitListenerErrorHandler { _, _, _ -> + fun eh() = RabbitListenerErrorHandler { _, _, _, _ -> this.ehLatch.countDown() "error processed" }