Search in sources :

Example 1 with ClientType

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);
}
Also used : ClientType(org.apache.eventmesh.common.protocol.grpc.protos.Heartbeat.ClientType) ConsumerManager(org.apache.eventmesh.runtime.core.protocol.grpc.consumer.ConsumerManager) Heartbeat(org.apache.eventmesh.common.protocol.grpc.protos.Heartbeat) RequestHeader(org.apache.eventmesh.common.protocol.grpc.protos.RequestHeader) AclException(org.apache.eventmesh.api.exception.AclException) ConsumerGroupClient(org.apache.eventmesh.runtime.core.protocol.grpc.consumer.consumergroup.ConsumerGroupClient) Date(java.util.Date)

Aggregations

Date (java.util.Date)1 AclException (org.apache.eventmesh.api.exception.AclException)1 Heartbeat (org.apache.eventmesh.common.protocol.grpc.protos.Heartbeat)1 ClientType (org.apache.eventmesh.common.protocol.grpc.protos.Heartbeat.ClientType)1 RequestHeader (org.apache.eventmesh.common.protocol.grpc.protos.RequestHeader)1 ConsumerManager (org.apache.eventmesh.runtime.core.protocol.grpc.consumer.ConsumerManager)1 ConsumerGroupClient (org.apache.eventmesh.runtime.core.protocol.grpc.consumer.consumergroup.ConsumerGroupClient)1