diff --git a/CHANGELOG.md b/CHANGELOG.md index 381a4b79a..5f3b6fa26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,4 +4,4 @@ - [feat: Add config address to report client url conversion.](https://github.com/Tencent/spring-cloud-tencent/pull/1795) - [feat: Update config server IP to 127.0.0.1 and adjust tests.](https://github.com/Tencent/spring-cloud-tencent/pull/1796) - [feat: Support Polaris config env value and add related tests](https://github.com/Tencent/spring-cloud-tencent/pull/1797) -- [refactor: modify the initialization of ApplicationContextAwareUtils.](https://github.com/Tencent/spring-cloud-tencent/pull/1778) +- [refactor: modify the initialization of ApplicationContextAwareUtils.](https://github.com/Tencent/spring-cloud-tencent/pull/1798) diff --git a/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/service/CalleeServiceChangeCallback.java b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/service/CalleeServiceChangeCallback.java new file mode 100644 index 000000000..c68e8fc75 --- /dev/null +++ b/spring-cloud-tencent-examples/quickstart-example/quickstart-callee-service-b/src/main/java/com/tencent/cloud/quickstart/callee/service/CalleeServiceChangeCallback.java @@ -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 currentServiceInstances, List addServiceInstances, List 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 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(); + } +}