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.
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