From 73829d99619e1cc39dfe71467b7c98986360ac7f Mon Sep 17 00:00:00 2001 From: renxb Date: Sat, 11 May 2024 13:40:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E8=BF=81=E7=A7=BBrpc=20boot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../caf-boot-starter-rpc-extension/pom.xml | 4 ++++ .../rpc/interceptor/RpcContextFilter.java | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) rename caf-boot-starters/{caf-boot-starter-rpc/src/main/java/io/iec/edp/caf => caf-boot-starter-rpc-extension/src/main/java/io/iec/edp}/rpc/interceptor/RpcContextFilter.java (59%) diff --git a/caf-boot-starters/caf-boot-starter-rpc-extension/pom.xml b/caf-boot-starters/caf-boot-starter-rpc-extension/pom.xml index a3b0d606..5271d82b 100644 --- a/caf-boot-starters/caf-boot-starter-rpc-extension/pom.xml +++ b/caf-boot-starters/caf-boot-starter-rpc-extension/pom.xml @@ -34,6 +34,10 @@ io.iec.edp caf-rpc-extension + + io.iec.edp + caf-tenancy-core + \ No newline at end of file diff --git a/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/interceptor/RpcContextFilter.java b/caf-boot-starters/caf-boot-starter-rpc-extension/src/main/java/io/iec/edp/rpc/interceptor/RpcContextFilter.java similarity index 59% rename from caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/interceptor/RpcContextFilter.java rename to caf-boot-starters/caf-boot-starter-rpc-extension/src/main/java/io/iec/edp/rpc/interceptor/RpcContextFilter.java index a67a86d1..8e4d8b16 100644 --- a/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/interceptor/RpcContextFilter.java +++ b/caf-boot-starters/caf-boot-starter-rpc-extension/src/main/java/io/iec/edp/rpc/interceptor/RpcContextFilter.java @@ -1,4 +1,21 @@ -package io.iec.edp.caf.rpc.interceptor; +/* + * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd. + * + * Licensed 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 io.iec.edp.rpc.interceptor; import io.iec.edp.caf.boot.context.CAFBizContextHolder; import io.iec.edp.caf.boot.context.CAFContext; -- Gitee From 30621ac3247ad6ea99be4ccb209b9197cd109dea Mon Sep 17 00:00:00 2001 From: renxb Date: Sat, 11 May 2024 15:36:51 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=B0=83=E6=95=B4rpc=20boot=E4=BE=9D?= =?UTF-8?q?=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/CafRpcExtensionConfiguration.java | 5 ++ .../caf/rpc/config/GrpcAutoConfiguration.java | 29 +++++++---- .../config/RpcClientAutoConfiguration.java | 50 +++++++------------ .../config/RpcRegistryAutoConfiguration.java | 12 ++++- .../config/RpcServerAutoConfiguration.java | 28 +++++++---- 5 files changed, 71 insertions(+), 53 deletions(-) diff --git a/caf-boot-starters/caf-boot-starter-rpc-extension/src/main/java/io/iec/edp/rpc/config/CafRpcExtensionConfiguration.java b/caf-boot-starters/caf-boot-starter-rpc-extension/src/main/java/io/iec/edp/rpc/config/CafRpcExtensionConfiguration.java index d1c8ffd7..4703ba24 100644 --- a/caf-boot-starters/caf-boot-starter-rpc-extension/src/main/java/io/iec/edp/rpc/config/CafRpcExtensionConfiguration.java +++ b/caf-boot-starters/caf-boot-starter-rpc-extension/src/main/java/io/iec/edp/rpc/config/CafRpcExtensionConfiguration.java @@ -21,6 +21,7 @@ import io.iec.edp.caf.rpc.api.filter.RpcClientFilter; import io.iec.edp.caf.rpc.api.filter.RpcServerFilter; import io.iec.edp.caf.rpc.extension.filter.SessionRpcClientFilter; import io.iec.edp.caf.rpc.extension.filter.SessionRpcServerFilter; +import io.iec.edp.rpc.interceptor.RpcContextFilter; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -37,4 +38,8 @@ public class CafRpcExtensionConfiguration { return new SessionRpcClientFilter(); } + @Bean + public RpcServerFilter rpcContextServerInterceptor(){ + return new RpcContextFilter(); + } } diff --git a/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/config/GrpcAutoConfiguration.java b/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/config/GrpcAutoConfiguration.java index dd94356f..b0fec5a8 100644 --- a/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/config/GrpcAutoConfiguration.java +++ b/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/config/GrpcAutoConfiguration.java @@ -1,11 +1,6 @@ package io.iec.edp.caf.rpc.config; import io.grpc.BindableService; -import io.grpc.ClientInterceptor; -import io.grpc.ServerInterceptor; -import io.iec.edp.caf.msu.api.ServiceUnitAwareService; -import io.iec.edp.caf.msu.api.client.ServiceRegistry; -import io.iec.edp.caf.msu.api.entity.MsuProperties; import io.iec.edp.caf.rpc.api.event.RpcClientEventBroker; import io.iec.edp.caf.rpc.api.filter.RpcClientFilter; import io.iec.edp.caf.rpc.api.filter.RpcServerFilter; @@ -27,19 +22,31 @@ import org.springframework.core.annotation.Order; public class GrpcAutoConfiguration { +// @Order(value = Ordered.HIGHEST_PRECEDENCE) +// @Bean +// public ApplicationListener grpcStartupListener(ServiceRegistry serviceRegistry, MsuProperties configuration) { +// return new GrpcServiceRegistryListener(serviceRegistry,configuration); +// } @Order(value = Ordered.HIGHEST_PRECEDENCE) @Bean - public ApplicationListener grpcStartupListener(ServiceRegistry serviceRegistry, MsuProperties configuration) { - return new GrpcServiceRegistryListener(serviceRegistry,configuration); + public ApplicationListener grpcStartupListener() { + return new GrpcServiceRegistryListener(); } +// @Bean +// public CAFRpcClient cafRpcClient(RpcClientEventBroker clientEventBroker, +// InternalServiceManageService management, +// RpcLocalInvoker rpcLocalInvoker, +// ITenantService tenantService, +// ITenantRouteService tenantRouteService){ +// return new CAFRpcClientImpl(clientEventBroker,management,rpcLocalInvoker,tenantService,tenantRouteService); +// } + @Bean public CAFRpcClient cafRpcClient(RpcClientEventBroker clientEventBroker, InternalServiceManageService management, - RpcLocalInvoker rpcLocalInvoker, - ITenantService tenantService, - ITenantRouteService tenantRouteService){ - return new CAFRpcClientImpl(clientEventBroker,management,rpcLocalInvoker,tenantService,tenantRouteService); + RpcLocalInvoker rpcLocalInvoker){ + return new CAFRpcClientImpl(clientEventBroker,management,rpcLocalInvoker); } @Bean diff --git a/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/config/RpcClientAutoConfiguration.java b/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/config/RpcClientAutoConfiguration.java index c2de1f1b..6c38e4a3 100644 --- a/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/config/RpcClientAutoConfiguration.java +++ b/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/config/RpcClientAutoConfiguration.java @@ -20,8 +20,6 @@ package io.iec.edp.caf.rpc.config; import io.iec.edp.caf.commons.event.config.EventListenerData; import io.iec.edp.caf.commons.event.config.EventListenerSettings; import io.iec.edp.caf.commons.event.config.EventManagerData; -import io.iec.edp.caf.core.context.ICAFContextService; -import io.iec.edp.caf.msu.api.ServiceUnitAwareService; import io.iec.edp.caf.rpc.api.event.RpcClientEventBroker; import io.iec.edp.caf.rpc.api.event.RpcClientEventManager; import io.iec.edp.caf.rpc.api.event.RpcServerEventBroker; @@ -31,21 +29,12 @@ import io.iec.edp.caf.rpc.api.service.InternalServiceManageService; import io.iec.edp.caf.rpc.api.service.RpcClient; import io.iec.edp.caf.rpc.client.RpcClassHolder; import io.iec.edp.caf.rpc.client.RpcClientImpl; -import io.iec.edp.caf.rpc.client.event.RpcStartupCompletedListener; import io.iec.edp.caf.rpc.client.local.RpcLocalInvoker; import io.iec.edp.caf.rpc.client.local.RpcLocalInvokerImpl; -import io.iec.edp.caf.rpc.remote.http.discover.RpcAddressDiscover; import io.iec.edp.caf.rpc.server.invoker.RpcRemoteInvoker; -import io.iec.edp.caf.tenancy.api.ITenantRouteService; -import io.iec.edp.caf.tenancy.api.ITenantService; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.context.ApplicationListener; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Lazy; -import org.springframework.core.Ordered; -import org.springframework.core.annotation.Order; import java.util.ArrayList; import java.util.List; @@ -56,17 +45,6 @@ import java.util.List; }) public class RpcClientAutoConfiguration { - @Value("${msu.enable:false}") - private Boolean msuEnabled; - - - @Order(value = Ordered.HIGHEST_PRECEDENCE) - @Bean - @Lazy(false) - public ApplicationListener rpcStartupListener() { - return new RpcStartupCompletedListener(msuEnabled); - } - /** * InternalSvrManagement Bean * @@ -82,9 +60,13 @@ public class RpcClientAutoConfiguration { * @return * @ */ +// @Bean +// public RpcClient createRpcClient(InternalServiceManageService management, RpcLocalInvoker rpcLocalInvoker, RpcRemoteInvoker rpcRemoteInvoker, ServiceUnitAwareService serviceUnitAware, ITenantService tenantService, ITenantRouteService tenantRouteService,RpcAddressDiscover rpcAddressDiscover) { +// return new RpcClientImpl(management, rpcLocalInvoker, rpcRemoteInvoker, serviceUnitAware,tenantService, tenantRouteService,rpcAddressDiscover); +// } @Bean - public RpcClient createRpcClient(InternalServiceManageService management, RpcLocalInvoker rpcLocalInvoker, RpcRemoteInvoker rpcRemoteInvoker, ServiceUnitAwareService serviceUnitAware, ITenantService tenantService, ITenantRouteService tenantRouteService,RpcAddressDiscover rpcAddressDiscover) { - return new RpcClientImpl(management, rpcLocalInvoker, rpcRemoteInvoker, serviceUnitAware,tenantService, tenantRouteService,rpcAddressDiscover); + public RpcClient createRpcClient(InternalServiceManageService management, RpcLocalInvoker rpcLocalInvoker, RpcRemoteInvoker rpcRemoteInvoker) { + return new RpcClientImpl(management, rpcLocalInvoker, rpcRemoteInvoker); } @@ -106,13 +88,19 @@ public class RpcClientAutoConfiguration { } - @Bean - public RpcLocalInvoker rpcLocalInvoker(RpcClientEventBroker clientEventBroker, - RpcServerEventBroker serverEventBroker, - ICAFContextService cafContextService, - RPCConfigurationProperties properties) { - return new RpcLocalInvokerImpl(clientEventBroker,serverEventBroker,cafContextService,properties); - } +// @Bean +// public RpcLocalInvoker rpcLocalInvoker(RpcClientEventBroker clientEventBroker, +// RpcServerEventBroker serverEventBroker, +// ICAFContextService cafContextService, +// RPCConfigurationProperties properties) { +// return new RpcLocalInvokerImpl(clientEventBroker,serverEventBroker,cafContextService,properties); +// } +@Bean +public RpcLocalInvoker rpcLocalInvoker(RpcClientEventBroker clientEventBroker, + RpcServerEventBroker serverEventBroker, + RPCConfigurationProperties properties) { + return new RpcLocalInvokerImpl(clientEventBroker,serverEventBroker,properties); +} @Bean public EventManagerData createRpcClientManagerData() { diff --git a/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/config/RpcRegistryAutoConfiguration.java b/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/config/RpcRegistryAutoConfiguration.java index 13de4f4f..07361701 100644 --- a/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/config/RpcRegistryAutoConfiguration.java +++ b/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/config/RpcRegistryAutoConfiguration.java @@ -14,8 +14,10 @@ * limitations under the License. */ -package io.iec.edp.caf.rpc.registry.storage.database.config; +//package io.iec.edp.caf.rpc.registry.storage.database.config; +package io.iec.edp.caf.rpc.config; +import io.iec.edp.caf.rpc.client.event.RpcStartupCompletedListener; import io.iec.edp.caf.rpc.registry.api.RpcDefinitionQuery; import io.iec.edp.caf.rpc.registry.api.RpcDefinitionRegistry; import io.iec.edp.caf.rpc.registry.impl.RpcDefinitionQueryImpl; @@ -45,9 +47,17 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories; @EnableJpaRepositories("io.iec.edp.caf.rpc.registry.storage.database.domain.repository") @EntityScan("io.iec.edp.caf.rpc.registry.storage.database.domain.entity") public class RpcRegistryAutoConfiguration { + @Value("${msu.enable:false}") + private Boolean msuEnabled; private RpcDefinitionStorage rpcDefinitionStorage; + @Order(value = Ordered.HIGHEST_PRECEDENCE) + @Bean + @Lazy(false) + public ApplicationListener rpcStartupListener() { + return new RpcStartupCompletedListener(msuEnabled); + } public RpcRegistryAutoConfiguration(RpcServiceDefinitionRepository rpcServiceDefinitionRepository, RpcServiceMethodDefinitionRepository rpcServiceMethodDefinitionRepository) { RpcDefinitionManager manager = new RpcDefinitionManager(rpcServiceDefinitionRepository, rpcServiceMethodDefinitionRepository); this.rpcDefinitionStorage = new RpcDefinitionStorageDatabaseImpl(manager); diff --git a/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/config/RpcServerAutoConfiguration.java b/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/config/RpcServerAutoConfiguration.java index 1852eed7..7c146a93 100644 --- a/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/config/RpcServerAutoConfiguration.java +++ b/caf-boot-starters/caf-boot-starter-rpc/src/main/java/io/iec/edp/caf/rpc/config/RpcServerAutoConfiguration.java @@ -20,9 +20,6 @@ package io.iec.edp.caf.rpc.config; import io.iec.edp.caf.commons.event.config.EventListenerData; import io.iec.edp.caf.commons.event.config.EventListenerSettings; import io.iec.edp.caf.commons.event.config.EventManagerData; -import io.iec.edp.caf.core.context.ICAFContextService; -import io.iec.edp.caf.msu.api.client.ServiceDiscovery; -import io.iec.edp.caf.msu.api.entity.MsuProperties; import io.iec.edp.caf.rest.server.RESTEndpointUtil; import io.iec.edp.caf.rpc.api.event.RpcClientEventBroker; import io.iec.edp.caf.rpc.api.event.RpcServerEventBroker; @@ -59,10 +56,19 @@ public class RpcServerAutoConfiguration { // return new RESTEndpoint("/runtime/communication/v1.0/rpc", rest); // } +// @Bean +//// @ConditionalOnBean(RpcServerEventBroker.class) +// public RpcServiceApi createRpcServerApi(Bus bus, RpcServer rpcServer, ICAFContextService cafContext, RpcServerEventBroker serverEventBroker) { +// RpcServiceApi service = new RpcServiceApiImpl(rpcServer, serverEventBroker, cafContext); +// //发布RESTService +// RESTEndpointUtil.createJAXRSServerWithInterceptor("/runtime/communication/v1.0/rpc", bus, +// Arrays.asList(service), Arrays.asList(new AuthorizingInterceptor())); +// return service; +// } @Bean -// @ConditionalOnBean(RpcServerEventBroker.class) - public RpcServiceApi createRpcServerApi(Bus bus, RpcServer rpcServer, ICAFContextService cafContext, RpcServerEventBroker serverEventBroker) { - RpcServiceApi service = new RpcServiceApiImpl(rpcServer, serverEventBroker, cafContext); + // @ConditionalOnBean(RpcServerEventBroker.class) + public RpcServiceApi createRpcServerApi(Bus bus, RpcServer rpcServer, RpcServerEventBroker serverEventBroker) { + RpcServiceApi service = new RpcServiceApiImpl(rpcServer, serverEventBroker); //发布RESTService RESTEndpointUtil.createJAXRSServerWithInterceptor("/runtime/communication/v1.0/rpc", bus, Arrays.asList(service), Arrays.asList(new AuthorizingInterceptor())); @@ -85,10 +91,12 @@ public class RpcServerAutoConfiguration { return new RpcServerEventBroker(manager, settings); } - @Bean - public RpcAddressDiscover createRpcAddressDiscover(MsuProperties properties, ServiceDiscovery serviceDiscovery) { - return new CenterAddressDiscover(properties, serviceDiscovery); - } +// 该bean这次改造后没再使用了,该bean是内部用的,先暂时不发布。 +// @Bean +// public RpcAddressDiscover createRpcAddressDiscover(MsuProperties properties, ServiceDiscovery serviceDiscovery) { +// return new CenterAddressDiscover(properties, serviceDiscovery); +// } + @Bean public RpcRemoteInvoker createRpcRemoteInvoker(RpcClientEventBroker clientEventBroker) { -- Gitee