Signed-off-by: Haotian Zhang <928016560@qq.com>pull/1778/head
parent
939f0f4386
commit
ed95d17af4
@ -1,9 +1,10 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.tencent.cloud.common.util.inet.PolarisInetUtilsAutoConfiguration,\
|
||||
com.tencent.cloud.common.util.ApplicationContextAwareUtils,\
|
||||
com.tencent.cloud.common.metadata.config.MetadataAutoConfiguration,\
|
||||
com.tencent.cloud.common.metadata.endpoint.PolarisMetadataEndpointAutoConfiguration,\
|
||||
com.tencent.cloud.common.async.PolarisAsyncPropertiesAutoConfiguration,\
|
||||
com.tencent.cloud.common.async.PolarisAsyncConfiguration
|
||||
org.springframework.cloud.bootstrap.BootstrapConfiguration=\
|
||||
com.tencent.cloud.common.util.inet.PolarisInetUtilsBootstrapConfiguration
|
||||
org.springframework.context.ApplicationContextInitializer=\
|
||||
com.tencent.cloud.common.util.ApplicationContextAwareUtils
|
||||
|
||||
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Tencent is pleased to support the open source community by making spring-cloud-tencent available.
|
||||
*
|
||||
* Copyright (C) 2021 Tencent. All rights reserved.
|
||||
*
|
||||
* Licensed under the BSD 3-Clause License (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://opensource.org/licenses/BSD-3-Clause
|
||||
*
|
||||
* 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 com.tencent.cloud.quickstart.callee.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.tencent.cloud.polaris.discovery.refresh.ServiceInstanceChangeCallback;
|
||||
import com.tencent.cloud.polaris.discovery.refresh.ServiceInstanceChangeListener;
|
||||
import com.tencent.polaris.api.pojo.Instance;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* Call back for QuickstartCalleeService.
|
||||
*
|
||||
* @author Haotian Zhang
|
||||
*/
|
||||
@Component
|
||||
@ServiceInstanceChangeListener(serviceName = "QuickstartCalleeService")
|
||||
public class CalleeServiceChangeCallback implements ServiceInstanceChangeCallback {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CalleeServiceChangeCallback.class);
|
||||
|
||||
@Override
|
||||
public void callback(List<Instance> currentServiceInstances, List<Instance> addServiceInstances, List<Instance> deleteServiceInstances) {
|
||||
String current = generateNodeList(currentServiceInstances);
|
||||
String add = generateNodeList(addServiceInstances);
|
||||
String delete = generateNodeList(deleteServiceInstances);
|
||||
LOG.info("current: {}, add: {}, delete: {}", current, add, delete);
|
||||
}
|
||||
|
||||
private String generateNodeList(List<Instance> deleteServiceInstances) {
|
||||
StringBuilder nodeListStr = new StringBuilder("[");
|
||||
for (Instance instance : deleteServiceInstances) {
|
||||
if (nodeListStr.length() > 1) {
|
||||
nodeListStr.append(", ");
|
||||
}
|
||||
nodeListStr.append(instance.getHost()).append(":").append(instance.getPort());
|
||||
}
|
||||
nodeListStr.append("]");
|
||||
return nodeListStr.toString();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue