use of org.apache.eventmesh.runtime.core.protocol.tcp.client.recommend.EventMeshRecommendImpl in project incubator-eventmesh by apache.
the class RecommendTask method run.
@Override
public void run() {
long taskExecuteTime = System.currentTimeMillis();
Package res = new Package();
try {
if (!eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshServerRegistryEnable) {
throw new Exception("registry enable config is false, not support");
}
UserAgent user = (UserAgent) pkg.getBody();
validateUserAgent(user);
String group = getGroupOfClient(user);
EventMeshRecommendStrategy eventMeshRecommendStrategy = new EventMeshRecommendImpl(eventMeshTCPServer);
String eventMeshRecommendResult = eventMeshRecommendStrategy.calculateRecommendEventMesh(group, user.getPurpose());
res.setHeader(new Header(RECOMMEND_RESPONSE, OPStatus.SUCCESS.getCode(), OPStatus.SUCCESS.getDesc(), pkg.getHeader().getSeq()));
res.setBody(eventMeshRecommendResult);
} catch (Exception e) {
messageLogger.error("RecommendTask failed|address={}|errMsg={}", ctx.channel().remoteAddress(), e);
res.setHeader(new Header(RECOMMEND_RESPONSE, OPStatus.FAIL.getCode(), e.toString(), pkg.getHeader().getSeq()));
} finally {
writeAndFlush(res, startTime, taskExecuteTime, session.getContext(), session);
// session.write2Client(res);
}
}
use of org.apache.eventmesh.runtime.core.protocol.tcp.client.recommend.EventMeshRecommendImpl in project incubator-eventmesh by apache.
the class QueryRecommendEventMeshHandler method handle.
@Override
public void handle(HttpExchange httpExchange) throws IOException {
String result = "";
OutputStream out = httpExchange.getResponseBody();
try {
if (!eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshServerRegistryEnable) {
throw new Exception("registry enable config is false, not support");
}
String queryString = httpExchange.getRequestURI().getQuery();
Map<String, String> queryStringInfo = NetUtils.formData2Dic(queryString);
String group = queryStringInfo.get(EventMeshConstants.MANAGE_GROUP);
String purpose = queryStringInfo.get(EventMeshConstants.MANAGE_PURPOSE);
if (StringUtils.isBlank(group) || StringUtils.isBlank(purpose)) {
httpExchange.sendResponseHeaders(200, 0);
result = "params illegal!";
out.write(result.getBytes());
return;
}
EventMeshRecommendStrategy eventMeshRecommendStrategy = new EventMeshRecommendImpl(eventMeshTCPServer);
String recommendEventMeshResult = eventMeshRecommendStrategy.calculateRecommendEventMesh(group, purpose);
result = (recommendEventMeshResult == null) ? "null" : recommendEventMeshResult;
logger.info("recommend eventmesh:{},group:{},purpose:{}", result, group, purpose);
httpExchange.sendResponseHeaders(200, 0);
out.write(result.getBytes());
} catch (Exception e) {
logger.error("QueryRecommendEventMeshHandler fail...", e);
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
logger.warn("out close failed...", e);
}
}
}
}
Aggregations