From a65de25572786ce788c2c9d6acf7380671be65a1 Mon Sep 17 00:00:00 2001 From: Venil Noronha Date: Mon, 18 Sep 2017 00:30:37 -0700 Subject: [PATCH] INT-4343: Add executor option to the RedisInChA JIRA: https://jira.springsource.org/browse/INT-4343 * Add a `Executor` setter named `setTaskExecutor` in `RedisInboundChannelAdapter` to set the container's task executor. * Add a `task-executor` attribute to ``. * Update RedisInboundChannelAdapterParser configuration validation tests. * Update redis.adoc and whats-new.adoc. * Polishing according PR comments * Improve `RedisQueueGatewayIntegrationTests` performance --- .../config/RedisInboundChannelAdapterParser.java | 5 ++++- .../redis/inbound/RedisInboundChannelAdapter.java | 9 ++++++++- .../redis/config/spring-integration-redis-5.0.xsd | 13 +++++++++++++ ...disInboundChannelAdapterParserTests-context.xml | 9 ++++++++- .../RedisInboundChannelAdapterParserTests.java | 14 +++++++++++++- .../RedisQueueGatewayIntegrationTests-context.xml | 7 +++---- .../config/RedisQueueGatewayIntegrationTests.java | 9 ++++----- src/reference/asciidoc/redis.adoc | 4 +++- src/reference/asciidoc/whats-new.adoc | 2 ++ 9 files changed, 58 insertions(+), 14 deletions(-) diff --git a/spring-integration-redis/src/main/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParser.java b/spring-integration-redis/src/main/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParser.java index 2a22976734..dba95b84f5 100644 --- a/spring-integration-redis/src/main/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParser.java +++ b/spring-integration-redis/src/main/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2017 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. @@ -31,6 +31,8 @@ import org.springframework.util.StringUtils; * @author Mark Fisher * @author Gary Russell * @author Artem Bilan + * @author Venil Noronha + * * @since 2.1 */ public class RedisInboundChannelAdapterParser extends AbstractChannelAdapterParser { @@ -49,6 +51,7 @@ public class RedisInboundChannelAdapterParser extends AbstractChannelAdapterPars IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-channel"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converter"); IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "serializer", true); + IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "task-executor"); return builder.getBeanDefinition(); } diff --git a/spring-integration-redis/src/main/java/org/springframework/integration/redis/inbound/RedisInboundChannelAdapter.java b/spring-integration-redis/src/main/java/org/springframework/integration/redis/inbound/RedisInboundChannelAdapter.java index 3775962003..c072f27615 100644 --- a/spring-integration-redis/src/main/java/org/springframework/integration/redis/inbound/RedisInboundChannelAdapter.java +++ b/spring-integration-redis/src/main/java/org/springframework/integration/redis/inbound/RedisInboundChannelAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2016 the original author or authors. + * Copyright 2007-2017 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,6 +18,7 @@ package org.springframework.integration.redis.inbound; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Executor; import org.springframework.beans.factory.BeanFactoryAware; import org.springframework.data.redis.connection.RedisConnectionFactory; @@ -39,6 +40,8 @@ import org.springframework.util.Assert; * @author Oleg Zhurakousky * @author Gary Russell * @author Artem Bilan + * @author Venil Noronha + * * @since 2.1 */ public class RedisInboundChannelAdapter extends MessageProducerSupport { @@ -75,6 +78,10 @@ public class RedisInboundChannelAdapter extends MessageProducerSupport { this.messageConverter = messageConverter; } + public void setTaskExecutor(Executor taskExecutor) { + this.container.setTaskExecutor(taskExecutor); + } + @Override public String getComponentType() { return "redis:inbound-channel-adapter"; diff --git a/spring-integration-redis/src/main/resources/org/springframework/integration/redis/config/spring-integration-redis-5.0.xsd b/spring-integration-redis/src/main/resources/org/springframework/integration/redis/config/spring-integration-redis-5.0.xsd index d1f530cd13..f30e11bc02 100644 --- a/spring-integration-redis/src/main/resources/org/springframework/integration/redis/config/spring-integration-redis-5.0.xsd +++ b/spring-integration-redis/src/main/resources/org/springframework/integration/redis/config/spring-integration-redis-5.0.xsd @@ -193,6 +193,19 @@ + + + + + + + + + + diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests-context.xml b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests-context.xml index e95d84e7b4..b562c99d90 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests-context.xml +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests-context.xml @@ -9,7 +9,14 @@ + serializer="serializer" + task-executor="executor" /> + + + + + + diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests.java index 4f4144a9b1..af8fd60183 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisInboundChannelAdapterParserTests.java @@ -22,6 +22,8 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertThat; +import java.util.concurrent.Executor; + import org.hamcrest.Matchers; import org.junit.Test; import org.junit.runner.RunWith; @@ -49,6 +51,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Mark Fisher * @author Gary Russell * @author Gunnar Hillert + * @author Venil Noronha */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -61,9 +64,13 @@ public class RedisInboundChannelAdapterParserTests extends RedisAvailableTests { @Autowired private MessageChannel autoChannel; - @Autowired @Qualifier("autoChannel.adapter") + @Autowired + @Qualifier("autoChannel.adapter") private RedisInboundChannelAdapter autoChannelAdapter; + @Autowired + private Executor executor; + @Test public void validateConfiguration() { RedisInboundChannelAdapter adapter = context.getBean("adapter", RedisInboundChannelAdapter.class); @@ -76,6 +83,10 @@ public class RedisInboundChannelAdapterParserTests extends RedisAvailableTests { assertEquals(converterBean, accessor.getPropertyValue("messageConverter")); assertEquals(context.getBean("serializer"), accessor.getPropertyValue("serializer")); + Object container = accessor.getPropertyValue("container"); + DirectFieldAccessor containerAccessor = new DirectFieldAccessor(container); + assertSame(this.executor, containerAccessor.getPropertyValue("taskExecutor")); + Object bean = context.getBean("withoutSerializer.adapter"); assertNotNull(bean); assertNull(TestUtils.getPropertyValue(bean, "serializer")); @@ -109,6 +120,7 @@ public class RedisInboundChannelAdapterParserTests extends RedisAvailableTests { @SuppressWarnings("unused") private static class TestMessageConverter extends SimpleMessageConverter { + } } diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisQueueGatewayIntegrationTests-context.xml b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisQueueGatewayIntegrationTests-context.xml index 836fd30791..690ac2f941 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisQueueGatewayIntegrationTests-context.xml +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisQueueGatewayIntegrationTests-context.xml @@ -26,16 +26,15 @@ + request-timeout="200"/> diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisQueueGatewayIntegrationTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisQueueGatewayIntegrationTests.java index e9d5f52aa2..ffdf95292f 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisQueueGatewayIntegrationTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/config/RedisQueueGatewayIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2016 the original author or authors. + * Copyright 2014-2017 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. @@ -39,16 +39,15 @@ import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; import org.springframework.messaging.support.GenericMessage; import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** * @author David Liu * @author Artem Bilan + * * @since 4.1 */ -@ContextConfiguration -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @DirtiesContext public class RedisQueueGatewayIntegrationTests extends RedisAvailableTests { diff --git a/src/reference/asciidoc/redis.adoc b/src/reference/asciidoc/redis.adoc index 865da1887b..5a3c477383 100644 --- a/src/reference/asciidoc/redis.adoc +++ b/src/reference/asciidoc/redis.adoc @@ -132,7 +132,7 @@ The default is a `SimpleMessageConverter`. Inbound adapters can subscribe to multiple topic names hence the comma-delimited set of values in the `topics` attribute. -Since _Spring Integration 3.0_, the Inbound Adapter, in addition to the existing `topics` attribute, now has the `topic-patterns` attribute. +Since _version 3.0_, the Inbound Adapter, in addition to the existing `topics` attribute, now has the `topic-patterns` attribute. This attribute contains a comma-delimited set of Redis topic patterns. For more information regarding Redis publish/subscribe, see http://redis.io/topics/pubsub[Redis Pub/Sub]. @@ -140,6 +140,8 @@ Inbound adapters can use a `RedisSerializer` to deserialize the body of Redis Me The `serializer` attribute of the `` can be set to an empty string, which results in a `null` value for the `RedisSerializer` property. In this case the raw `byte[]` bodies of Redis Messages are provided as the message payloads. +Since _version 5.0_, an `Executor` instance can be provided to the Inbound Adapter via the `task-executor` attribute of the ``. + [[redis-outbound-channel-adapter]] ==== Redis Outbound Channel Adapter diff --git a/src/reference/asciidoc/whats-new.adoc b/src/reference/asciidoc/whats-new.adoc index a37df6187b..4a12edbdf2 100644 --- a/src/reference/asciidoc/whats-new.adoc +++ b/src/reference/asciidoc/whats-new.adoc @@ -265,6 +265,8 @@ The `RedisStoreWritingMessageHandler` is supplied now with additional String-bas The `zsetIncrementExpression` can now be configured on the `RedisStoreWritingMessageHandler`, as well. In addition this property has been changed from `true` to `false` since `INCR` option on `ZADD` Redis command is optional. +The `RedisInboundChannelAdapter` can now be supplied with an `Executor` for executing Redis listener invokers. + See <> for more information. ==== TCP Changes