moremind commented on code in PR #6057: URL: https://github.com/apache/shenyu/pull/6057#discussion_r2312788882
########## shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/InstanceController.java: ########## @@ -88,6 +103,33 @@ public ShenyuAdminResult detailInstanceInfo(@PathVariable("id") final String id) return ShenyuAdminResult.success(ShenyuResultMessage.DETAIL_SUCCESS, instanceInfoVO); } + /** + * receive beat. + * + * @param instanceBeatInfoDTO instanceBeatInfoDTO. + * @return {@linkplain ShenyuAdminResult} + */ + @PostMapping("/beat") + public String beat(@Valid @RequestBody final InstanceBeatInfoDTO instanceBeatInfoDTO) { + //todo:admin集群模式下,请求转发给master节点 Review Comment: remove the Chinese comments, and complete the task ########## shenyu-bootstrap/src/main/resources/application.yml: ########## @@ -194,10 +194,12 @@ shenyu: # workerCount: 8 # daemon: true register: - enabled: false - registerType: zookeeper #etcd #consul - serverLists: localhost:2181 #http://localhost:2379 #localhost:8848 + enable: true Review Comment: why change the config? ########## shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/InstanceController.java: ########## @@ -72,6 +80,13 @@ public ShenyuAdminResult queryPlugins(@RequestParam(name = "instanceType", requi namespaceId ) ); + commonPager.getDataList().forEach(instanceInfoVO -> { Review Comment: just by CollectionUtils.isNotEmpty ########## shenyu-register-center/shenyu-register-client-beat/src/main/java/org/apache/shenyu/register/client/beat/HeartbeatListener.java: ########## @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.shenyu.register.client.beat; + +import org.apache.shenyu.common.concurrent.ShenyuThreadFactory; +import org.apache.shenyu.common.config.ShenyuConfig; +import org.apache.shenyu.common.constant.InstanceTypeConstants; +import org.apache.shenyu.common.utils.IpUtils; +import org.apache.shenyu.common.utils.SystemInfoUtils; +import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository; +import org.apache.shenyu.register.common.dto.InstanceBeatInfoDTO; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.web.ServerProperties; +import org.springframework.context.event.ContextClosedEvent; +import org.springframework.context.event.EventListener; + +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.TimeUnit; + +public class HeartbeatListener { + + private static final Logger LOG = LoggerFactory.getLogger(HeartbeatListener.class); + + private ScheduledThreadPoolExecutor executor; + + private final ShenyuClientRegisterRepository httpClientRegisterRepository; + + private final ShenyuConfig shenyuConfig; + + public HeartbeatListener(final ShenyuClientRegisterRepository httpClientRegisterRepository, final ShenyuConfig shenyuConfig, final ServerProperties serverProperties) { + executor = new ScheduledThreadPoolExecutor(1, ShenyuThreadFactory.create("scheduled-instance-task", false)); + this.httpClientRegisterRepository = httpClientRegisterRepository; + this.shenyuConfig = shenyuConfig; + LOG.info("Web server initialized on port {}, starting heartbeat reporter", serverProperties.getPort()); + //启动心跳任务 + executor.scheduleAtFixedRate(() -> { + InstanceBeatInfoDTO instanceBeatInfoDTO = new InstanceBeatInfoDTO(); + instanceBeatInfoDTO.setInstancePort(serverProperties.getPort() + ""); + instanceBeatInfoDTO.setInstanceIp(IpUtils.getHost()); + instanceBeatInfoDTO.setNamespaceId(shenyuConfig.getNamespace()); + instanceBeatInfoDTO.setInstanceInfo(SystemInfoUtils.getSystemInfo()); + instanceBeatInfoDTO.setInstanceType(InstanceTypeConstants.BOOTSTRAP_INSTANCE_INFO); + httpClientRegisterRepository.sendHeartbeat(instanceBeatInfoDTO); + }, 0, 5, TimeUnit.SECONDS + ); Review Comment: format the code -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@shenyu.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org