Search in sources :

Example 31 with StringRedisSerializer

use of org.springframework.data.redis.serializer.StringRedisSerializer in project spring-integration by spring-projects.

the class RedisQueueOutboundChannelAdapterTests method testInt3015Default.

@Test
@RedisAvailable
public void testInt3015Default() throws Exception {
    final String queueName = "si.test.testRedisQueueOutboundChannelAdapter";
    final RedisQueueOutboundChannelAdapter handler = new RedisQueueOutboundChannelAdapter(queueName, this.connectionFactory);
    String payload = "testing";
    handler.handleMessage(MessageBuilder.withPayload(payload).build());
    RedisTemplate<String, ?> redisTemplate = new StringRedisTemplate();
    redisTemplate.setConnectionFactory(this.connectionFactory);
    redisTemplate.afterPropertiesSet();
    Object result = redisTemplate.boundListOps(queueName).rightPop(5000, TimeUnit.MILLISECONDS);
    assertNotNull(result);
    assertEquals(payload, result);
    Date payload2 = new Date();
    handler.handleMessage(MessageBuilder.withPayload(payload2).build());
    RedisTemplate<String, ?> redisTemplate2 = new RedisTemplate<String, Object>();
    redisTemplate2.setConnectionFactory(this.connectionFactory);
    redisTemplate2.setEnableDefaultSerializer(false);
    redisTemplate2.setKeySerializer(new StringRedisSerializer());
    redisTemplate2.setValueSerializer(new JdkSerializationRedisSerializer());
    redisTemplate2.afterPropertiesSet();
    Object result2 = redisTemplate2.boundListOps(queueName).rightPop(5000, TimeUnit.MILLISECONDS);
    assertNotNull(result2);
    assertEquals(payload2, result2);
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisTemplate(org.springframework.data.redis.core.RedisTemplate) JdkSerializationRedisSerializer(org.springframework.data.redis.serializer.JdkSerializationRedisSerializer) Date(java.util.Date) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Example 32 with StringRedisSerializer

use of org.springframework.data.redis.serializer.StringRedisSerializer in project spring-integration by spring-projects.

the class RedisStoreWritingMessageHandlerTests method initTemplate.

private <K, V> RedisTemplate<K, V> initTemplate(RedisConnectionFactory rcf, RedisTemplate<K, V> redisTemplate) {
    redisTemplate.setConnectionFactory(rcf);
    redisTemplate.setKeySerializer(new StringRedisSerializer());
    redisTemplate.afterPropertiesSet();
    return redisTemplate;
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer)

Example 33 with StringRedisSerializer

use of org.springframework.data.redis.serializer.StringRedisSerializer in project spring-integration by spring-projects.

the class AggregatorWithRedisLocksTests method createTemplate.

private RedisTemplate<String, ?> createTemplate() {
    RedisTemplate<String, ?> template = new RedisTemplate<String, Object>();
    template.setConnectionFactory(this.getConnectionFactoryForTest());
    template.setKeySerializer(new StringRedisSerializer());
    template.afterPropertiesSet();
    return template;
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) RedisTemplate(org.springframework.data.redis.core.RedisTemplate)

Example 34 with StringRedisSerializer

use of org.springframework.data.redis.serializer.StringRedisSerializer in project spring-integration by spring-projects.

the class RedisStoreWritingMessageHandler method onInit.

@Override
protected void onInit() throws Exception {
    this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory());
    Assert.state(!this.mapKeyExpressionExplicitlySet || (this.collectionType == CollectionType.MAP || this.collectionType == CollectionType.PROPERTIES), "'mapKeyExpression' can only be set for CollectionType.MAP or CollectionType.PROPERTIES");
    if (!this.redisTemplateExplicitlySet) {
        if (!this.extractPayloadElements) {
            RedisTemplate<String, Object> template = new RedisTemplate<>();
            StringRedisSerializer serializer = new StringRedisSerializer();
            template.setKeySerializer(serializer);
            template.setHashKeySerializer(serializer);
            this.redisTemplate = template;
        }
        this.redisTemplate.setConnectionFactory(this.connectionFactory);
        this.redisTemplate.afterPropertiesSet();
    }
    this.initialized = true;
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) StringRedisTemplate(org.springframework.data.redis.core.StringRedisTemplate) RedisTemplate(org.springframework.data.redis.core.RedisTemplate)

Example 35 with StringRedisSerializer

use of org.springframework.data.redis.serializer.StringRedisSerializer in project spring-integration by spring-projects.

the class RedisQueueGatewayIntegrationTests method testRequestReplyWithMessage.

@Test
@RedisAvailable
public void testRequestReplyWithMessage() throws Exception {
    this.inboundGateway.setSerializer(new JdkSerializationRedisSerializer());
    this.inboundGateway.setExtractPayload(false);
    this.outboundGateway.setSerializer(new JdkSerializationRedisSerializer());
    this.outboundGateway.setExtractPayload(false);
    this.sendChannel.send(new GenericMessage<Integer>(2));
    Message<?> receive = this.outputChannel.receive(10000);
    assertNotNull(receive);
    assertEquals(3, receive.getPayload());
    this.inboundGateway.setSerializer(new StringRedisSerializer());
    this.inboundGateway.setExtractPayload(true);
    this.outboundGateway.setSerializer(new StringRedisSerializer());
    this.outboundGateway.setExtractPayload(true);
}
Also used : StringRedisSerializer(org.springframework.data.redis.serializer.StringRedisSerializer) JdkSerializationRedisSerializer(org.springframework.data.redis.serializer.JdkSerializationRedisSerializer) RedisAvailable(org.springframework.integration.redis.rules.RedisAvailable) Test(org.junit.Test)

Aggregations

StringRedisSerializer (org.springframework.data.redis.serializer.StringRedisSerializer)46 RedisTemplate (org.springframework.data.redis.core.RedisTemplate)30 Bean (org.springframework.context.annotation.Bean)17 StringRedisTemplate (org.springframework.data.redis.core.StringRedisTemplate)16 Test (org.junit.Test)14 JdkSerializationRedisSerializer (org.springframework.data.redis.serializer.JdkSerializationRedisSerializer)14 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)13 DataAccessException (org.springframework.dao.DataAccessException)7 RedisConnection (org.springframework.data.redis.connection.RedisConnection)7 RedisCallback (org.springframework.data.redis.core.RedisCallback)7 BeanFactory (org.springframework.beans.factory.BeanFactory)5 Date (java.util.Date)4 QueueChannel (org.springframework.integration.channel.QueueChannel)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Jackson2JsonRedisSerializer (org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer)3 Message (org.springframework.messaging.Message)3 PollableChannel (org.springframework.messaging.PollableChannel)3 ErrorMessage (org.springframework.messaging.support.ErrorMessage)3 HashMap (java.util.HashMap)2