12.3. 初始化监听器
Redisson Node提供了在启动完成后,执行RedissonNodeInitializer
指定的初始化监听器的机制。这个机制可以用在启动完成时执行注册在类路径(classpath)中分布式远程服务的实现,或其他必要业务逻辑。比如,通知其他订阅者关于一个新节点上线的通知:
public class MyRedissonNodeInitializer implements RedissonNodeInitializer {
@Override
public void onStartup(RedissonNode redissonNode) {
RMap<String, Integer> map = redissonNode.getRedisson().getMap("myMap");
// ...
// 或
redisson.getRemoteService("myRemoteService").register(MyRemoteService.class, new MyRemoteServiceImpl(...));
// 或
reidsson.getTopic("myNotificationTopic").publish("New node has joined. id:" + redissonNode.getId() + " remote-server:" + redissonNode.getRemoteAddress());
}
}