use of org.apache.eventmesh.common.protocol.grpc.protos.Heartbeat in project incubator-eventmesh by apache.
the class HeartbeatProcessor method doAclCheck.
private void doAclCheck(Heartbeat heartbeat) throws AclException {
RequestHeader header = heartbeat.getHeader();
if (eventMeshGrpcServer.getEventMeshGrpcConfiguration().eventMeshServerSecurityEnable) {
String remoteAdd = header.getIp();
String user = header.getUsername();
String pass = header.getPassword();
String sys = header.getSys();
int requestCode = Integer.valueOf(RequestCode.HEARTBEAT.getRequestCode());
for (Heartbeat.HeartbeatItem item : heartbeat.getHeartbeatItemsList()) {
Acl.doAclCheckInHttpHeartbeat(remoteAdd, user, pass, sys, item.getTopic(), requestCode);
}
}
}
use of org.apache.eventmesh.common.protocol.grpc.protos.Heartbeat 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);
}
use of org.apache.eventmesh.common.protocol.grpc.protos.Heartbeat in project incubator-eventmesh by apache.
the class EventMeshGrpcConsumer method heartBeat.
private void heartBeat() {
RequestHeader header = EventMeshClientUtil.buildHeader(clientConfig, EventMeshCommon.EM_MESSAGE_PROTOCOL_NAME);
scheduler.scheduleAtFixedRate(() -> {
if (subscriptionMap.isEmpty()) {
return;
}
Heartbeat.Builder heartbeatBuilder = Heartbeat.newBuilder().setHeader(header).setConsumerGroup(clientConfig.getConsumerGroup()).setClientType(Heartbeat.ClientType.SUB);
for (Map.Entry<String, String> entry : subscriptionMap.entrySet()) {
Heartbeat.HeartbeatItem heartbeatItem = Heartbeat.HeartbeatItem.newBuilder().setTopic(entry.getKey()).setUrl(entry.getValue()).build();
heartbeatBuilder.addHeartbeatItems(heartbeatItem);
}
Heartbeat heartbeat = heartbeatBuilder.build();
try {
Response response = heartbeatClient.heartbeat(heartbeat);
if (logger.isDebugEnabled()) {
logger.debug("Grpc Consumer Heartbeat response: {}", response);
}
} catch (Exception e) {
logger.error("Error in sending out heartbeat. error {}", e.getMessage());
}
}, 10000, EventMeshCommon.HEARTBEAT, TimeUnit.MILLISECONDS);
logger.info("Grpc Consumer Heartbeat started.");
}
Aggregations