1 配置
@Bean
public Ignite ignite(){
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setIgniteInstanceName(BFaceConstants.IGNITE_NAME);
cfg.setPeerClassLoadingEnabled(true);
cfg.setGridLogger(new Slf4jLogger());
return Ignition.start(cfg);
}
2 监听
public void listen(){
Ignite ignite = Ignition.ignite(BFaceConstants.IGNITE_NAME);
IgniteMessaging rmtMsg = ignite.message();
rmtMsg.localListen(BFaceConstants.FACE_MESSAGING, (nodeId, msg) -> {
logger.info("Received ordered message from " + nodeId);
if(Objects.isNull(msg)){
return true;
}
String fileName = String.valueOf(msg);
FaceRecognition.recog(new File(fileName));
//new Thread(() -> FaceRecognition.recog(new File(fileName))).start();
return true;
});
}
3 发送消息
@Override
public void fileCreated(int wd, String rootPath, String name) {
String filePath = rootPath + File.separator + name;
File file = new File(filePath);
if(!BFaceHelper.isSupportedImage(name)){
logger.info("文件{}不支持的格式",filePath);
if(!file.isDirectory()){
logger.info("删除{}", file.delete());
}
return;
}
//发送识别请求
Ignite ignite = Ignition.ignite(BFaceConstants.IGNITE_NAME);
IgniteMessaging messaging = ignite.message();
messaging.sendOrdered(BFaceConstants.FACE_MESSAGING, filePath, BFaceConstants.FACE_MESSAGING_TIMEOUT);
}