From d2eba0927de18a8a38c12d7ec7d1d29f9519adaf Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Wed, 27 Jan 2016 17:32:22 -0500 Subject: [PATCH] INT-3939: Consistency for Redis Queue Gateways JIRA: https://jira.spring.io/browse/INT-3939 Previously `RedisQueueInboundGateway` and `RedisQueueOutboundGateway` used different `RedisSerializer`s for non-String objects. * Change the default to the `JdkSerializationRedisSerializer` for the consistency in case of client/server scenarios. The previous behavior with the `StringRedisSerializer` can be reinstated with `serializer` injection. Doc Polishing. --- .../redis/inbound/RedisQueueInboundGateway.java | 5 +++-- .../redis/outbound/RedisQueueOutboundGateway.java | 6 +++--- .../config/RedisQueueGatewayIntegrationTests-context.xml | 9 ++------- .../redis/config/RedisQueueGatewayIntegrationTests.java | 8 ++++---- src/reference/asciidoc/redis.adoc | 3 ++- src/reference/asciidoc/whats-new.adoc | 8 ++++++++ 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/spring-integration-redis/src/main/java/org/springframework/integration/redis/inbound/RedisQueueInboundGateway.java b/spring-integration-redis/src/main/java/org/springframework/integration/redis/inbound/RedisQueueInboundGateway.java index b42c44ed65..760570aed7 100644 --- a/spring-integration-redis/src/main/java/org/springframework/integration/redis/inbound/RedisQueueInboundGateway.java +++ b/spring-integration-redis/src/main/java/org/springframework/integration/redis/inbound/RedisQueueInboundGateway.java @@ -25,6 +25,7 @@ import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.BoundListOperations; import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; import org.springframework.integration.channel.MessagePublishingErrorHandler; @@ -69,7 +70,7 @@ public class RedisQueueInboundGateway extends MessagingGatewaySupport implements private volatile Executor taskExecutor; - private volatile RedisSerializer serializer = new StringRedisSerializer(); + private volatile RedisSerializer serializer = new JdkSerializationRedisSerializer(); private volatile long receiveTimeout = DEFAULT_RECEIVE_TIMEOUT; @@ -84,7 +85,7 @@ public class RedisQueueInboundGateway extends MessagingGatewaySupport implements private volatile Runnable stopCallback; /** - * @param queueName Must not be an empty String + * @param queueName Must not be an empty String * @param connectionFactory Must not be null */ public RedisQueueInboundGateway(String queueName, RedisConnectionFactory connectionFactory) { diff --git a/spring-integration-redis/src/main/java/org/springframework/integration/redis/outbound/RedisQueueOutboundGateway.java b/spring-integration-redis/src/main/java/org/springframework/integration/redis/outbound/RedisQueueOutboundGateway.java index a2481c57d1..ac9b9eb260 100644 --- a/spring-integration-redis/src/main/java/org/springframework/integration/redis/outbound/RedisQueueOutboundGateway.java +++ b/spring-integration-redis/src/main/java/org/springframework/integration/redis/outbound/RedisQueueOutboundGateway.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors + * Copyright 2014-2016 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. @@ -84,7 +84,7 @@ public class RedisQueueOutboundGateway extends AbstractReplyProducingMessageHand @Override public String getComponentType() { - return "redis:queue-outbound-gatewway"; + return "redis:queue-outbound-gateway"; } @Override @@ -111,7 +111,7 @@ public class RedisQueueOutboundGateway extends AbstractReplyProducingMessageHand BoundListOperations boundListOperations = template.boundListOps(uuid + QUEUE_NAME_SUFFIX); byte[] reply = (byte[]) boundListOperations.rightPop(this.receiveTimeout, TimeUnit.MILLISECONDS); - if(reply != null && reply.length > 0) { + if (reply != null && reply.length > 0) { Object replyMessage = this.serializer.deserialize(reply); if (replyMessage == null) { return null; 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 bd4dccba7d..21ac79d59f 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 @@ -28,20 +28,15 @@ queue="#{redisQueue.toString()}" reply-timeout="1000" requires-reply="true" - reply-channel="outputChannel" - serializer="serializer"/> - - - + reply-channel="outputChannel"/> - + 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 5870931d09..9cea3ca495 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 @@ -78,10 +78,10 @@ public class RedisQueueGatewayIntegrationTests extends RedisAvailableTests { @Test @RedisAvailable public void testRequestWithReply() throws Exception { - this.sendChannel.send(new GenericMessage("test1")); + this.sendChannel.send(new GenericMessage(1)); Message receive = this.outputChannel.receive(10000); assertNotNull(receive); - assertEquals("test1".toUpperCase(), receive.getPayload()); + assertEquals(2, receive.getPayload()); } @Test @@ -124,10 +124,10 @@ public class RedisQueueGatewayIntegrationTests extends RedisAvailableTests { this.inboundGateway.setExtractPayload(false); this.outboundGateway.setSerializer(new JdkSerializationRedisSerializer()); this.outboundGateway.setExtractPayload(false); - this.sendChannel.send(new GenericMessage("test1")); + this.sendChannel.send(new GenericMessage(2)); Message receive = this.outputChannel.receive(10000); assertNotNull(receive); - assertEquals("test1".toUpperCase(), receive.getPayload()); + assertEquals(3, receive.getPayload()); this.inboundGateway.setSerializer(new StringRedisSerializer()); this.inboundGateway.setExtractPayload(true); this.outboundGateway.setSerializer(new StringRedisSerializer()); diff --git a/src/reference/asciidoc/redis.adoc b/src/reference/asciidoc/redis.adoc index 2636d93064..933b17ce8e 100644 --- a/src/reference/asciidoc/redis.adoc +++ b/src/reference/asciidoc/redis.adoc @@ -732,7 +732,8 @@ Mutually exclusive with 'redis-template' attribute. <8> The `RedisSerializer` bean reference. Can be an empty string, which means 'no serializer'. In this case the raw `byte[]` from the inbound Redis message is sent to the `channel` as the `Message` payload. -By default it is a `StringRedisSerializer`. +By default it is a `JdkSerializationRedisSerializer`. (Note that in releases before _version 4.3_, it was a +`StringRedisSerializer` by default; to restore that behavior provide a reference to a `StringRedisSerializer`). <9> The timeout in milliseconds to wait until the receive message will be get or not. diff --git a/src/reference/asciidoc/whats-new.adoc b/src/reference/asciidoc/whats-new.adoc index 1a122acf56..d1bf6ed7b9 100644 --- a/src/reference/asciidoc/whats-new.adoc +++ b/src/reference/asciidoc/whats-new.adoc @@ -80,12 +80,20 @@ See <> for more information. ==== Redis Changes +===== List Push/Pop Direction + Previously, the queue channel adapters always used the Redis List in a fixed direction, pushing to the left end and reading from the right end. It is now possible to configure the reading and writing direction using `rightPop` and `leftPush` options for the `RedisQueueMessageDrivenEndpoint` and `RedisQueueOutboundChannelAdapter` respectively. See <> and <> for more information. +===== Queue Inbound Gateway Default Serializer + +The default serializer in the inbound gateway has been changed to a `JdkSerializationRedisSerializer` for compatibility +with the outbound gateway. +See <> for more information. + ==== HTTP Changes Previously, with requests that had a body (such as `POST`) that had no `content-type` header, the body was ignored.