Skip to content

Instantly share code, notes, and snippets.

@mp911de
Created December 9, 2016 09:58
Show Gist options
  • Select an option

  • Save mp911de/3d5f1d9fa1efa105044e51f2ceb9648f to your computer and use it in GitHub Desktop.

Select an option

Save mp911de/3d5f1d9fa1efa105044e51f2ceb9648f to your computer and use it in GitHub Desktop.
public class MyRedisMessageSubscriber extends RedisMessageSubscriber {
static final Action2<Message, byte[]> ACTION = new Action2<Message, byte[]>() {
ObjectMapper objectMapper = new ObjectMapper();
@Override
public void call(Message message, byte[] bytes) {
try {
String result = objectMapper.readValue(message.getBody(), String.class);
logger.info("received:" + result);
} catch (IOException e) {
e.printStackTrace();
}
}
};
public MyRedisMessageSubscriber() {
super(ACTION);
}
}
public abstract class RedisMessageSubscriber implements MessageListener {
protected static Logger logger = LogManager.getLogger(RedisMessageSubscriber.class);
// action inspect here
private final Action2<Message, byte[]> action;
public RedisMessageSubscriber(Action2<Message, byte[]> action) {
this.action = action;
}
@Override
public void onMessage(Message message, byte[] bytes) {
logger.info("===> redis subscribe message in <===");
action.call(message, bytes);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment