public class RedisSubscriber extends RouteBuilder {
@Value("${redis.host}")
private String redisHost;
@Value("${redis.port}")
private int redisPort;
@Value("${redis.channel.mychannel}")
private String redisChannel;
private Object bean;
private String method;
@Required
public void setBean(Object bean) {
this.bean = bean;
}
@Required
public void setMethod(String method) {
this.method = method;
}
@Override
public void configure() throws Exception {
from(String.format("spring-redis://%s:%s?command=SUBSCRIBE&channels=%s&serializer=#%s", redisHost, redisPort, redisChannel, ManagedCamel.REDIS_SERIALIZER))
.log(String.format("Consuming with redis in channel: %s, massage body: ${body}", redisChannel))
.process(exchange -> {
}).bean(bean, String.format("%s(${body})", method));
}
}
The Method 'method' inside the injected bean will handle the massages recived.