use of org.apache.eventmesh.common.protocol.grpc.protos.Heartbeat.ClientType in project incubator-eventmesh by apache.
the class HeartbeatProcessor method process.
public void process(Heartbeat heartbeat, EventEmitter<Response> emitter) throws Exception {
RequestHeader header = heartbeat.getHeader();
if (!ServiceUtils.validateHeader(header)) {
ServiceUtils.sendRespAndDone(StatusCode.EVENTMESH_PROTOCOL_HEADER_ERR, emitter);
return;
}
if (!ServiceUtils.validateHeartBeat(heartbeat)) {
ServiceUtils.sendRespAndDone(StatusCode.EVENTMESH_PROTOCOL_BODY_ERR, emitter);
return;
}
try {
doAclCheck(heartbeat);
} catch (AclException e) {
aclLogger.warn("CLIENT HAS NO PERMISSION, HeartbeatProcessor failed", e);
ServiceUtils.sendRespAndDone(StatusCode.EVENTMESH_ACL_ERR, e.getMessage(), emitter);
return;
}
// only handle heartbeat for consumers
ClientType clientType = heartbeat.getClientType();
if (!ClientType.SUB.equals(clientType)) {
ServiceUtils.sendRespAndDone(StatusCode.EVENTMESH_PROTOCOL_BODY_ERR, emitter);
return;
}
ConsumerManager consumerManager = eventMeshGrpcServer.getConsumerManager();
String consumerGroup = heartbeat.getConsumerGroup();
// update clients' timestamp in the heartbeat items
for (Heartbeat.HeartbeatItem item : heartbeat.getHeartbeatItemsList()) {
ConsumerGroupClient hbClient = ConsumerGroupClient.builder().env(header.getEnv()).idc(header.getIdc()).sys(header.getSys()).ip(header.getIp()).pid(header.getPid()).consumerGroup(consumerGroup).topic(item.getTopic()).lastUpTime(new Date()).build();
consumerManager.updateClientTime(hbClient);
}
ServiceUtils.sendRespAndDone(StatusCode.SUCCESS, "heartbeat success", emitter);
}
Aggregations