Redis serialization prefixed with extra string

落爺英雄遲暮 提交于 2019-12-07 09:28:28

问题


Camel-Redis's serializer is prefixing extra characters to message key.

When I checked the DB, the message key shows something like..

"\xac\xed\x00\x05t\x00\x11test150827171118"

As you can see, the string "\xac\xed\x00\x05t\x00\x11"

is prefixed for key "test150827171118".

I tried two patterns,

Firstly, I set the serializer in the registry directly.

Registry.put("serializer", new StringRedisSerializer());

Second pattern is by setting in the RedisTemplate first. Then putting the redis template in the registry.

RedisTemplate<?, ?> template = new RedisTemplate<>();
template.setKeySerializer(new StringRedisSerializer());
template.setValueSerializer(new StringRedisSerializer());
registry.put("redisTemplate", template);

Both cannot solve the problem of serizlization. Am I missing additional configuration for camel-redis.


回答1:


I finally found the answer after five or six hours of googling and implementing on my development machine.

Camel serializer URI options is only for CONSUMER. To affect PRODUCER, I also need to configure a custom RedisTemplate with StringRedisSerializer as default serializer.

redisTemplate.setDefaultSerializer(new StringRedisSerializer());

Then put both the serializer and redis template instance in registry and reference it from Camel URI.

registry.put("customTemplate", template);
registry.put("stringSerializer", new StringRedisSerializer());

Camel URI is like...

redis://<host>:<port>?redisTemplate=#customTemplate&serializer=#stringSerializer


来源:https://stackoverflow.com/questions/32245916/redis-serialization-prefixed-with-extra-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!