@@ -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<String, Declarable> getManualDeclarables() {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the manually declared AMQP objects.
|
||||
* @return the manually declared AMQP objects.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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<String, Declarable> getManualDeclarables() {
|
||||
Map<String, Declarable> 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<Declarable> getManualDeclarableSet() {
|
||||
return Collections.unmodifiableSet(this.manualDeclarables);
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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}",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -151,7 +151,7 @@ class EnableRabbitKotlinTests {
|
||||
val ehLatch = CountDownLatch(1)
|
||||
|
||||
@Bean
|
||||
fun eh() = RabbitListenerErrorHandler { _, _, _ ->
|
||||
fun eh() = RabbitListenerErrorHandler { _, _, _, _ ->
|
||||
this.ehLatch.countDown()
|
||||
"error processed"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user