Redis: Wrong serialization using the camel-redis

camel-spring redis example
spring data redis
spring boot-starter-data redis example
redistemplate
spring boot redis cache example mkyong
spring data redis order by
redis in spring mvc
spring data redis custom query

I'm playing with camel and redis. I have a very short route:

from("timer://foo?period=5s")
    .to("http://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_day.geojson")
    .split().method(SplitFeatures.class,"splitMessage")
    .to("spring-redis://localhost:6379?command=SET&serializer=#serializer");

Where splitMessage is the following:

public static List<Message> splitMessage(@Body String body) throws IOException {

    List<Message> answer = new ArrayList<Message>();
    JsonParser parser=new JsonParser();
    JsonObject jo=(JsonObject)parser.parse(body);

    // I care only for the features array
    JsonArray features=jo.get("features").getAsJsonArray();

    for (JsonElement feature: features) {
         Message msg=new DefaultMessage();
         JsonObject jof=feature.getAsJsonObject();

         // get the key
         String id=jof.get("id").getAsString().toString();

         System.out.print(id);
         msg.setHeader(RedisConstants.KEY, id);
         msg.setHeader(RedisConstants.VALUE, jof.toString());
         answer.add(msg);
    }
    return answer;
}

Everything runs smoothly, but when I check the redis db I see that the key is:

 "\xac\xed\x00\x05t\x00\nci11361338"

and the same prefix "\xac\xed\x00\x05t\x00" is in the value.

Obviously the those printed by the System.out look fine.

As you see I tried to add a serializer, a StringRedisSerializer that I defined in the Main like this:

    Main main = new Main();
main.bind("serializer", new StringRedisSerializer());

But the result is the same (also using GenericToStringSerializer).

Is there something I'm missing?

Just ran across this today. Using Camel 2.18.0 & camel-spring-redis all you need to do is create a bean to handle the appropriate serialization and pass it in to the camel producer definition.

  @Bean
  public RedisSerializer stringSerializer() {
    return new StringRedisSerializer();
  }

The sink statement is as per your original post

 .... 
 .to("spring-redis://localhost:6379?serializer=#stringSerializer");

Users - camel-redis strings serialization, questions/18698802/redis-wrong-serialization-using-the-camel-redis I'm As you see I tried to add a serializer, a StringRedisSerializer that I� Just ran across this today. Using Camel 2.18.0 & camel-spring-redis all you need to do is create a bean to handle the appropriate serialization and pass it in to the camel producer definition. @Bean public RedisSerializer stringSerializer() { return new StringRedisSerializer(); } The sink statement is as per your original post

I had a look at the source code and it seems that the custom serializer you are specifying is set only for consumers and not for producers. So the the serializer you created is not used in your case.

In the mean time, what you can do is create a RedisTemplate in the registry and set the serializer you want to it. Then let Camel use that RedisTemplate. That should configure Camel producer with the serializer you want.

Spring Redis :: Apache Camel, Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming The Spring Redis endpoint is configured using URI syntax: serializer (common). Teams. Q&A for Work. Stack Overflow for Teams is a private, secure spot for you and your coworkers to find and share information.

In spring dsl:

  <bean id="stringSerializer" class="org.springframework.data.redis.serializer.StringRedisSerializer"/>

...

      <marshal ref="json" />
      <convertBodyTo type="java.lang.String" charset="UTF-8"/>
    <setHeader headerName="CamelRedis.Value">
      <simple>${body}</simple>
    </setHeader>
    <to uri="spring-redis://{{redis.host}}:{{redis.port}}?command=SET&amp;serializer=#stringRedisSerializer"/>

Apache Camel Redis Example, To integrate Apache Camel with Redis NoSQL database. storing K/V in redis the data gets serialized using JDK default encoding which add class information <camelContext xmlns="http://camel.apache.org/schema/spring" trace="false"> � (2 replies) Apologies for the ugly original post. I have set up a simple route to isolate the string serialization problem that I am experiencing, like others, the problem where the default jdk serializer prepends "junk" at the start of the key and value, making it difficult/impossible to perform integration testing.

Pub/Sub using Camel + Redis, One of the challenges of using storing spring sessions in Redis is that the This approach ensures that every time a de-serialization error is�

Handling Deserialization errors in Spring Redis Sessions, Keys in Redis can only be Strings, but Spring lets you store java objects as well. By default, Spring will convert the java object using JDK�

How to fix Redis Keys Incorrectly Serialized With Java, INFO:*Prerequisites* In order to use this component, you must have a Redis server running. serializer (common) Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the�

Comments
  • I think it's now fixed for producers as well.