From ddccc08bdce1cd7ff2aea9d9e296fc9e55474b49 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Tue, 10 Mar 2020 13:44:47 -0400 Subject: [PATCH] Remove deprecations; fix corresponding schema - add `batch-size` - deprecate `transaction-size` - remove deprecated `publisher-confirms` - add 'consumer-batch-enabled' --- .../amqp/rabbit/junit/RepeatProcessor.java | 201 ------------------ ...bstractRabbitListenerContainerFactory.java | 13 -- .../config/ConnectionFactoryParser.java | 7 +- .../config/ListenerContainerFactoryBean.java | 13 +- .../rabbit/config/RabbitNamespaceUtils.java | 22 +- .../SimpleRabbitListenerContainerFactory.java | 12 +- .../MethodRabbitListenerEndpoint.java | 3 +- .../SimpleMessageListenerContainer.java | 14 -- .../listener/adapter/HandlerAdapter.java | 19 +- .../listener/adapter/InvocationResult.java | 11 +- .../adapter/MessageListenerAdapter.java | 22 +- .../amqp/rabbit/log4j2/AmqpAppender.java | 119 ++--------- .../amqp/rabbit/config/spring-rabbit-2.2.xsd | 40 ++-- .../config/ListenerContainerParserTests.java | 3 +- .../CachingConnectionFactoryTests.java | 32 +-- .../rabbit/log4j2/ExtendAmqpAppender.java | 7 +- .../ConnectionFactoryParserTests-context.xml | 2 +- .../ListenerContainerParserTests-context.xml | 3 +- 18 files changed, 88 insertions(+), 455 deletions(-) delete mode 100644 spring-rabbit-junit/src/main/java/org/springframework/amqp/rabbit/junit/RepeatProcessor.java diff --git a/spring-rabbit-junit/src/main/java/org/springframework/amqp/rabbit/junit/RepeatProcessor.java b/spring-rabbit-junit/src/main/java/org/springframework/amqp/rabbit/junit/RepeatProcessor.java deleted file mode 100644 index 0627dc86..00000000 --- a/spring-rabbit-junit/src/main/java/org/springframework/amqp/rabbit/junit/RepeatProcessor.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright 2002-2019 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. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.amqp.rabbit.junit; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; - -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Callable; -import java.util.concurrent.CompletionService; -import java.util.concurrent.ExecutorCompletionService; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.After; -import org.junit.Before; -import org.junit.internal.runners.statements.RunAfters; -import org.junit.internal.runners.statements.RunBefores; -import org.junit.rules.MethodRule; -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.Statement; -import org.junit.runners.model.TestClass; - -import org.springframework.core.annotation.AnnotationUtils; -import org.springframework.test.annotation.Repeat; - -/** - * A JUnit method @Rule that looks at Spring repeat annotations on methods and executes the test multiple times - * (without re-initializing the test case if necessary). To avoid re-initializing use the {@link #isInitialized()} - * method to protect the @Before and @After methods. - * @deprecated in favor of JUnit 5 {@link org.junit.jupiter.api.RepeatedTest}. - * - * @author Dave Syer - * - */ -@Deprecated -public class RepeatProcessor implements MethodRule { - - private static final Log LOGGER = LogFactory.getLog(RepeatProcessor.class); - - private final int concurrency; - - private volatile boolean initialized = false; - - private volatile boolean finalizing = false; - - public RepeatProcessor() { - this(0); - } - - public RepeatProcessor(int concurrency) { - this.concurrency = concurrency < 0 ? 0 : concurrency; - } - - @Override - public Statement apply(final Statement base, FrameworkMethod method, final Object target) { - - Repeat repeat = AnnotationUtils.findAnnotation(method.getMethod(), Repeat.class); - if (repeat == null) { - return base; - } - - final int repeats = repeat.value(); - if (repeats <= 1) { - return base; - } - - initializeIfNecessary(target); - - if (this.concurrency <= 0) { - return new Statement() { - @Override - public void evaluate() throws Throwable { - try { - for (int i = 0; i < repeats; i++) { - try { - base.evaluate(); - } - catch (Throwable t) { // NOSONAR - throw new IllegalStateException( - "Failed on iteration: " + i + " of " + repeats + " (started at 0)", t); - } - } - } - finally { - finalizeIfNecessary(target); - } - } - }; - } - return new Statement() { // NOSONAR - @Override - public void evaluate() throws Throwable { - List> results = new ArrayList>(); - ExecutorService executor = Executors.newFixedThreadPool(RepeatProcessor.this.concurrency); - CompletionService completionService = new ExecutorCompletionService(executor); - try { - for (int i = 0; i < repeats; i++) { - final int count = i; - results.add(completionService.submit(new Callable() { - @Override - public Boolean call() { - try { - base.evaluate(); - } - catch (Throwable t) { // NOSONAR - throw new IllegalStateException("Failed on iteration: " + count, t); - } - return true; - } - })); - } - for (int i = 0; i < repeats; i++) { - Future future = completionService.take(); - assertThat(future.get()).as("Null result from completer").isTrue(); - } - } - finally { - executor.shutdownNow(); - finalizeIfNecessary(target); - } - } - }; - } - - private void finalizeIfNecessary(Object target) { - this.finalizing = true; - List afters = new TestClass(target.getClass()).getAnnotatedMethods(After.class); - try { - if (!afters.isEmpty()) { - LOGGER.debug("Running @After methods"); - try { - new RunAfters(new Statement() { - @Override - public void evaluate() { - } - }, afters, target).evaluate(); - } - catch (Throwable e) { // NOSONAR - fail("Unexpected throwable " + e); - } - } - } - finally { - this.finalizing = false; - } - } - - private void initializeIfNecessary(Object target) { - TestClass testClass = new TestClass(target.getClass()); - List befores = testClass.getAnnotatedMethods(Before.class); - if (!befores.isEmpty()) { - LOGGER.debug("Running @Before methods"); - try { - new RunBefores(new Statement() { - @Override - public void evaluate() { - } - }, befores, target).evaluate(); - } - catch (Throwable e) { // NOSONAR - fail("Unexpected throwable " + e); - } - this.initialized = true; - } - if (!testClass.getAnnotatedMethods(After.class).isEmpty()) { - this.initialized = true; - } - } - - public boolean isInitialized() { - return this.initialized; - } - - public boolean isFinalizing() { - return this.finalizing; - } - - public int getConcurrency() { - return this.concurrency > 0 ? this.concurrency : 1; - } - -} diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/AbstractRabbitListenerContainerFactory.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/AbstractRabbitListenerContainerFactory.java index b28d9d13..3eee538b 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/AbstractRabbitListenerContainerFactory.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/AbstractRabbitListenerContainerFactory.java @@ -20,7 +20,6 @@ package org.springframework.amqp.rabbit.config; import java.util.Arrays; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; import org.aopalliance.aop.Advice; import org.apache.commons.logging.Log; @@ -346,18 +345,6 @@ public abstract class AbstractRabbitListenerContainerFactory configurer) { - this.containerCustomizer = container -> configurer.accept(container); - } - /** * Set a {@link ContainerCustomizer} that is invoked after a container is created and * configured to enable further customization of the container. diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/ConnectionFactoryParser.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/ConnectionFactoryParser.java index 25473e2c..cbb61174 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/ConnectionFactoryParser.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/ConnectionFactoryParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2020 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. @@ -50,7 +50,7 @@ class ConnectionFactoryParser extends AbstractSingleBeanDefinitionParser { private static final String EXECUTOR_ATTRIBUTE = "executor"; - private static final String PUBLISHER_CONFIRMS = "publisher-confirms"; + private static final String CONFIRM_TYPE = "confirm-type"; private static final String PUBLISHER_RETURNS = "publisher-returns"; @@ -101,7 +101,6 @@ class ConnectionFactoryParser extends AbstractSingleBeanDefinitionParser { NamespaceUtils.setReferenceIfAttributeDefined(builder, element, EXECUTOR_ATTRIBUTE); NamespaceUtils.setValueIfAttributeDefined(builder, element, ADDRESSES); NamespaceUtils.setValueIfAttributeDefined(builder, element, SHUFFLE_ADDRESSES); - NamespaceUtils.setValueIfAttributeDefined(builder, element, PUBLISHER_CONFIRMS); NamespaceUtils.setValueIfAttributeDefined(builder, element, PUBLISHER_RETURNS); NamespaceUtils.setValueIfAttributeDefined(builder, element, REQUESTED_HEARTBEAT, "requestedHeartBeat"); NamespaceUtils.setValueIfAttributeDefined(builder, element, CONNECTION_TIMEOUT); @@ -111,7 +110,7 @@ class ConnectionFactoryParser extends AbstractSingleBeanDefinitionParser { NamespaceUtils.setValueIfAttributeDefined(builder, element, FACTORY_TIMEOUT, "channelCheckoutTimeout"); NamespaceUtils.setValueIfAttributeDefined(builder, element, CONNECTION_LIMIT); NamespaceUtils.setReferenceIfAttributeDefined(builder, element, "connection-name-strategy"); - NamespaceUtils.setValueIfAttributeDefined(builder, element, "confirm-type", "publisherConfirmType"); + NamespaceUtils.setValueIfAttributeDefined(builder, element, CONFIRM_TYPE, "publisherConfirmType"); } } diff --git a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/ListenerContainerFactoryBean.java b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/ListenerContainerFactoryBean.java index cf5ee9ca..eab12baf 100644 --- a/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/ListenerContainerFactoryBean.java +++ b/spring-rabbit/src/main/java/org/springframework/amqp/rabbit/config/ListenerContainerFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 the original author or authors. + * Copyright 2016-2020 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. @@ -396,16 +396,6 @@ public class ListenerContainerFactoryBean extends AbstractFactoryBean layout, boolean ignoreExceptions, - AmqpManager manager, BlockingQueue eventQueue) { + Property[] properties, AmqpManager manager, BlockingQueue eventQueue) { - super(name, filter, layout, ignoreExceptions); + super(name, filter, layout, ignoreExceptions, properties); this.manager = manager; this.events = eventQueue; } - @Deprecated // For backward compatibility - @PluginFactory - public static AmqpAppender createAppender(// NOSONAR NCSS line count - @PluginConfiguration final Configuration configuration, - @PluginAttribute("name") String name, - @PluginElement("Layout") Layout layout, - @PluginElement("Filter") Filter filter, - @PluginAttribute("ignoreExceptions") boolean ignoreExceptions, - @PluginAttribute("uri") URI uri, - @PluginAttribute("host") String host, - @PluginAttribute("port") String port, - @PluginAttribute("addresses") String addresses, - @PluginAttribute("user") String user, - @PluginAttribute("password") String password, - @PluginAttribute("virtualHost") String virtualHost, - @PluginAttribute("useSsl") boolean useSsl, - @PluginAttribute("verifyHostname") boolean verifyHostname, - @PluginAttribute("sslAlgorithm") String sslAlgorithm, - @PluginAttribute("sslPropertiesLocation") String sslPropertiesLocation, - @PluginAttribute("keyStore") String keyStore, - @PluginAttribute("keyStorePassphrase") String keyStorePassphrase, - @PluginAttribute("keyStoreType") String keyStoreType, - @PluginAttribute("trustStore") String trustStore, - @PluginAttribute("trustStorePassphrase") String trustStorePassphrase, - @PluginAttribute("trustStoreType") String trustStoreType, - @PluginAttribute("saslConfig") String saslConfig, - @PluginAttribute("senderPoolSize") int senderPoolSize, - @PluginAttribute("maxSenderRetries") int maxSenderRetries, - @PluginAttribute("applicationId") String applicationId, - @PluginAttribute("routingKeyPattern") String routingKeyPattern, - @PluginAttribute("generateId") boolean generateId, - @PluginAttribute("deliveryMode") String deliveryMode, - @PluginAttribute("exchange") String exchange, - @PluginAttribute("exchangeType") String exchangeType, - @PluginAttribute("declareExchange") boolean declareExchange, - @PluginAttribute("durable") boolean durable, - @PluginAttribute("autoDelete") boolean autoDelete, - @PluginAttribute("contentType") String contentType, - @PluginAttribute("contentEncoding") String contentEncoding, - @PluginAttribute("connectionName") String connectionName, - @PluginAttribute("clientConnectionProperties") String clientConnectionProperties, - @PluginAttribute("async") boolean async, - @PluginAttribute("charset") String charset, - @PluginAttribute(value = "bufferSize", defaultInt = Integer.MAX_VALUE) int bufferSize, - @PluginElement(BlockingQueueFactory.ELEMENT_TYPE) BlockingQueueFactory blockingQueueFactory, - @PluginAttribute(value = "addMdcAsHeaders", defaultBoolean = true) boolean addMdcAsHeaders) { - - return new Builder() - .setConfiguration(configuration) - .setName(name) - .setLayout(layout) - .setFilter(filter) - .setIgnoreExceptions(ignoreExceptions) - .setUri(uri) - .setHost(host) - .setPort(port) - .setAddresses(addresses) - .setUser(user) - .setPassword(password) - .setVirtualHost(virtualHost) - .setUseSsl(useSsl) - .setVerifyHostname(verifyHostname) - .setSslAlgorithm(sslAlgorithm) - .setSslPropertiesLocation(sslPropertiesLocation) - .setKeyStore(keyStore) - .setKeyStorePassphrase(keyStorePassphrase) - .setKeyStoreType(keyStoreType) - .setTrustStore(trustStore) - .setTrustStorePassphrase(trustStorePassphrase) - .setTrustStoreType(trustStoreType) - .setSaslConfig(saslConfig) - .setSenderPoolSize(senderPoolSize) - .setMaxSenderRetries(maxSenderRetries) - .setApplicationId(applicationId) - .setRoutingKeyPattern(routingKeyPattern) - .setGenerateId(generateId) - .setDeliveryMode(deliveryMode) - .setExchange(exchange) - .setExchangeType(exchangeType) - .setDeclareExchange(declareExchange) - .setDurable(durable) - .setAutoDelete(autoDelete) - .setContentType(contentType) - .setContentEncoding(contentEncoding) - .setConnectionName(connectionName) - .setClientConnectionProperties(clientConnectionProperties) - .setAsync(async) - .setCharset(charset) - .setBufferSize(bufferSize) - .setBlockingQueueFactory(blockingQueueFactory) - .setAddMdcAsHeaders(addMdcAsHeaders) - .build(); - } - + /** + * Create a new builder. + * @return the builder. + */ @PluginBuilderFactory public static Builder newBuilder() { return new Builder(); @@ -1203,7 +1121,8 @@ public class AmqpAppender extends AbstractAppender { */ protected AmqpAppender buildInstance(String name, Filter filter, Layout layout, boolean ignoreExceptions, AmqpManager manager, BlockingQueue eventQueue) { - return new AmqpAppender(name, filter, layout, ignoreExceptions, manager, eventQueue); + + return new AmqpAppender(name, filter, layout, ignoreExceptions, Property.EMPTY_ARRAY, manager, eventQueue); } } diff --git a/spring-rabbit/src/main/resources/org/springframework/amqp/rabbit/config/spring-rabbit-2.2.xsd b/spring-rabbit/src/main/resources/org/springframework/amqp/rabbit/config/spring-rabbit-2.2.xsd index bcf1abb3..80d84333 100644 --- a/spring-rabbit/src/main/resources/org/springframework/amqp/rabbit/config/spring-rabbit-2.2.xsd +++ b/spring-rabbit/src/main/resources/org/springframework/amqp/rabbit/config/spring-rabbit-2.2.xsd @@ -736,9 +736,28 @@ + + + + + + + + + + + + + @@ -746,10 +765,11 @@ @@ -1464,14 +1484,6 @@ - - - - - layout, boolean ignoreExceptions, AmqpManager manager, BlockingQueue eventQueue, String foo, String bar) { - super(name, filter, layout, ignoreExceptions, manager, eventQueue); + super(name, filter, layout, ignoreExceptions, Property.EMPTY_ARRAY, manager, eventQueue); this.foo = foo; this.bar = bar; } diff --git a/spring-rabbit/src/test/resources/org/springframework/amqp/rabbit/config/ConnectionFactoryParserTests-context.xml b/spring-rabbit/src/test/resources/org/springframework/amqp/rabbit/config/ConnectionFactoryParserTests-context.xml index 90ef5660..bb4ed231 100644 --- a/spring-rabbit/src/test/resources/org/springframework/amqp/rabbit/config/ConnectionFactoryParserTests-context.xml +++ b/spring-rabbit/src/test/resources/org/springframework/amqp/rabbit/config/ConnectionFactoryParserTests-context.xml @@ -9,7 +9,7 @@ diff --git a/spring-rabbit/src/test/resources/org/springframework/amqp/rabbit/config/ListenerContainerParserTests-context.xml b/spring-rabbit/src/test/resources/org/springframework/amqp/rabbit/config/ListenerContainerParserTests-context.xml index d65302bd..4a126685 100644 --- a/spring-rabbit/src/test/resources/org/springframework/amqp/rabbit/config/ListenerContainerParserTests-context.xml +++ b/spring-rabbit/src/test/resources/org/springframework/amqp/rabbit/config/ListenerContainerParserTests-context.xml @@ -40,7 +40,8 @@ - +