Created
December 9, 2016 09:58
-
-
Save mp911de/3d5f1d9fa1efa105044e51f2ceb9648f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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