From 3e34cdf0301924604e826c0779ff41c4e89c03a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=96=AF=E7=8B=82=E7=9A=84=E7=8B=AE=E5=AD=90li?= <15040126243@163.com> Date: Tue, 23 Aug 2022 10:12:01 +0800 Subject: [PATCH] =?UTF-8?q?update=20dubbo=20=E5=8D=87=E7=BA=A7=203.1.0=20?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=87=AA=E8=A1=8C=E5=A4=84=E7=90=86=E7=9A=84?= =?UTF-8?q?=E6=BA=90=E7=A0=81=E4=BF=AE=E5=A4=8D=20=E9=87=87=E7=94=A8?= =?UTF-8?q?=E5=AE=98=E6=96=B9=E4=BF=AE=E5=A4=8D=E5=90=8E=E7=9A=84=E4=BB=A3?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ruoyi-common/ruoyi-common-alibaba-bom/pom.xml | 2 +- ruoyi-common/ruoyi-common-dubbo/pom.xml | 6 - .../registry/nacos/NacosServiceDiscovery.java | 147 ------------------ 3 files changed, 1 insertion(+), 154 deletions(-) delete mode 100644 ruoyi-common/ruoyi-common-dubbo/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscovery.java diff --git a/ruoyi-common/ruoyi-common-alibaba-bom/pom.xml b/ruoyi-common/ruoyi-common-alibaba-bom/pom.xml index 724c9f95..866576e3 100644 --- a/ruoyi-common/ruoyi-common-alibaba-bom/pom.xml +++ b/ruoyi-common/ruoyi-common-alibaba-bom/pom.xml @@ -23,7 +23,7 @@ 1.1.0 2.0.2 1.5.2 - 3.0.10 + 3.1.0 1.0.11 diff --git a/ruoyi-common/ruoyi-common-dubbo/pom.xml b/ruoyi-common/ruoyi-common-dubbo/pom.xml index 90172838..31a7a297 100644 --- a/ruoyi-common/ruoyi-common-dubbo/pom.xml +++ b/ruoyi-common/ruoyi-common-dubbo/pom.xml @@ -65,11 +65,5 @@ - - com.alibaba.nacos - nacos-client - true - - diff --git a/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscovery.java b/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscovery.java deleted file mode 100644 index 09efc2fa..00000000 --- a/ruoyi-common/ruoyi-common-dubbo/src/main/java/org/apache/dubbo/registry/nacos/NacosServiceDiscovery.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * 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.dubbo.registry.nacos; - -import com.alibaba.nacos.api.exception.NacosException; -import com.alibaba.nacos.api.naming.listener.NamingEvent; -import com.alibaba.nacos.api.naming.pojo.Instance; -import com.alibaba.nacos.api.naming.pojo.ListView; -import com.ruoyi.common.core.utils.SpringUtils; -import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.function.ThrowableFunction; -import org.apache.dubbo.common.logger.Logger; -import org.apache.dubbo.common.logger.LoggerFactory; -import org.apache.dubbo.registry.client.AbstractServiceDiscovery; -import org.apache.dubbo.registry.client.ServiceDiscovery; -import org.apache.dubbo.registry.client.ServiceInstance; -import org.apache.dubbo.registry.client.event.ServiceInstancesChangedEvent; -import org.apache.dubbo.registry.client.event.listener.ServiceInstancesChangedListener; -import org.apache.dubbo.registry.nacos.util.NacosNamingServiceUtils; -import org.apache.dubbo.rpc.model.ApplicationModel; - -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import static org.apache.dubbo.common.function.ThrowableConsumer.execute; -import static org.apache.dubbo.registry.nacos.util.NacosNamingServiceUtils.createNamingService; -import static org.apache.dubbo.registry.nacos.util.NacosNamingServiceUtils.toInstance; - -/** - * 覆盖 dubbo 源码 修复 `dubbo.registry.group` 配置项注册组不生效问题 - * - * Nacos {@link ServiceDiscovery} implementation - * - * @see ServiceDiscovery - * @since 2.7.5 - */ -public class NacosServiceDiscovery extends AbstractServiceDiscovery { - - private final String DUBBO_GROUP = SpringUtils.getProperty("dubbo.registry.group"); - - private final Logger logger = LoggerFactory.getLogger(getClass()); - - private NacosNamingServiceWrapper namingService; - - public NacosServiceDiscovery(ApplicationModel applicationModel, URL registryURL) { - super(applicationModel, registryURL); - this.namingService = createNamingService(registryURL); - } - - @Override - public void doDestroy() throws Exception { - this.namingService.shutdown(); - } - - @Override - public void doRegister(ServiceInstance serviceInstance) { - execute(namingService, service -> { - Instance instance = toInstance(serviceInstance); - // Should not register real group for ServiceInstance - // Or will cause consumer unable to fetch all of the providers from every group - // Provider's group is invisible for consumer - service.registerInstance(instance.getServiceName(), DUBBO_GROUP, instance); - }); - } - - @Override - public void doUnregister(ServiceInstance serviceInstance) throws RuntimeException { - execute(namingService, service -> { - Instance instance = toInstance(serviceInstance); - // Should not register real group for ServiceInstance - // Or will cause consumer unable to fetch all of the providers from every group - // Provider's group is invisible for consumer - service.deregisterInstance(instance.getServiceName(), DUBBO_GROUP, instance); - }); - } - - @Override - public Set getServices() { - return ThrowableFunction.execute(namingService, service -> { - // Should not register real group for ServiceInstance - // Or will cause consumer unable to fetch all of the providers from every group - // Provider's group is invisible for consumer - ListView view = service.getServicesOfServer(0, Integer.MAX_VALUE, DUBBO_GROUP); - return new LinkedHashSet<>(view.getData()); - }); - } - - @Override - public List getInstances(String serviceName) throws NullPointerException { - return ThrowableFunction.execute(namingService, service -> - service.selectInstances(serviceName, DUBBO_GROUP, true) - .stream().map((i) -> NacosNamingServiceUtils.toServiceInstance(registryURL, i)) - .collect(Collectors.toList()) - ); - } - - @Override - public void addServiceInstancesChangedListener(ServiceInstancesChangedListener listener) - throws NullPointerException, IllegalArgumentException { - // check if listener has already been added through another interface/service - if (!instanceListeners.add(listener)) { - return; - } - execute(namingService, service -> listener.getServiceNames().forEach(serviceName -> { - try { - service.subscribe(serviceName, DUBBO_GROUP, e -> { // Register Nacos EventListener - if (e instanceof NamingEvent) { - NamingEvent event = (NamingEvent) e; - handleEvent(event, listener); - } - }); - } catch (NacosException e) { - logger.error("add nacos service instances changed listener fail ", e); - } - })); - } - - @Override - public URL getUrl() { - return registryURL; - } - - private void handleEvent(NamingEvent event, ServiceInstancesChangedListener listener) { - String serviceName = event.getServiceName(); - List serviceInstances = event.getInstances() - .stream() - .map((i) -> NacosNamingServiceUtils.toServiceInstance(registryURL, i)) - .collect(Collectors.toList()); - listener.onEvent(new ServiceInstancesChangedEvent(serviceName, serviceInstances)); - } -}