You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@shenyu.apache.org by GitBox <gi...@apache.org> on 2021/06/20 11:45:06 UTC

[GitHub] [incubator-shenyu] KevinClair opened a new issue #1653: [refactor] Refactor code about different client register.

KevinClair opened a new issue #1653:
URL: https://github.com/apache/incubator-shenyu/issues/1653


   ## Feature Request
   
   <!-- First of all: Have you checked the docs https://dromara.org/projects/soul/, GitHub issues whether someone else has already reported your issue? Maybe the feature already exists?-->
   
   ```java
   public class MetadataExecutorSubscriber implements ExecutorTypeSubscriber<MetaDataRegisterDTO> {
       
       private final ShenyuClientRegisterService shenyuClientRegisterService;
       
       public MetadataExecutorSubscriber(final ShenyuClientRegisterService shenyuClientRegisterService) {
           this.shenyuClientRegisterService = shenyuClientRegisterService;
       }
       
       @Override
       public DataType getType() {
           return DataType.META_DATA;
       }
       
       @Override
        // If we want to add a new client,we need add a new check in this place.
       public void executor(final Collection<MetaDataRegisterDTO> metaDataRegisterDTOList) {
           for (MetaDataRegisterDTO metaDataRegisterDTO : metaDataRegisterDTOList) {
               if (metaDataRegisterDTO.getRpcType().equals(RpcTypeEnum.DUBBO.getName())) {
                   shenyuClientRegisterService.registerDubbo(metaDataRegisterDTO);
               } else if (metaDataRegisterDTO.getRpcType().equals(RpcTypeEnum.SOFA.getName())) {
                   shenyuClientRegisterService.registerSofa(metaDataRegisterDTO);
               } else if (metaDataRegisterDTO.getRpcType().equals(RpcTypeEnum.TARS.getName())) {
                   shenyuClientRegisterService.registerTars(metaDataRegisterDTO);
               } else if (metaDataRegisterDTO.getRpcType().equals(RpcTypeEnum.HTTP.getName())) {
                   shenyuClientRegisterService.registerSpringMvc(metaDataRegisterDTO);
               } else if (metaDataRegisterDTO.getRpcType().equals(RpcTypeEnum.SPRING_CLOUD.getName())) {
                   shenyuClientRegisterService.registerSpringCloud(metaDataRegisterDTO);
               } else if (metaDataRegisterDTO.getRpcType().equals(RpcTypeEnum.GRPC.getName())) {
                   shenyuClientRegisterService.registerGrpc(metaDataRegisterDTO);
               } else if (metaDataRegisterDTO.getRpcType().equals(RpcTypeEnum.MOTAN.getName())) {
                   shenyuClientRegisterService.registerMotan(metaDataRegisterDTO);
               }
           }
       }
   }
   ```
   
   #### Describe the solution you'd like
   
   * This is not a good way to scale;
   * We can implement different clients through the factory;
   ```java
   public interface ShenyuClientRegisterServiceFactory {
   
       /**
        * Register meta data.
        *
        * @param metaDataRegisterDTO meta data register dto.
        * @return the string
        */
       String register(MetaDataRegisterDTO metaDataRegisterDTO);
   
       /**
        * mvc uri upstream update.
        *
        * @param contextPath context paht
        * @param uriList     uri list
        * @return the string
        */
       String registerURI(String contextPath, List<String> uriList);
   }
   ```
   * You can add a new implement when you want to add a new client;
   ````java
   public class MetadataExecutorSubscriber implements ExecutorTypeSubscriber<MetaDataRegisterDTO> {
   
       private final Map<String, ShenyuClientRegisterServiceFactory> shenyuClientRegisterService;
   
       public MetadataExecutorSubscriber(final Map<String, ShenyuClientRegisterServiceFactory> shenyuClientRegisterService) {
           this.shenyuClientRegisterService = shenyuClientRegisterService;
       }
   
       @Override
       public DataType getType() {
           return DataType.META_DATA;
       }
       
       @Override
       public void executor(final Collection<MetaDataRegisterDTO> metaDataRegisterDTOList) {
           for (MetaDataRegisterDTO metaDataRegisterDTO : metaDataRegisterDTOList) {
               // There is no need to modify this place.
               shenyuClientRegisterService.get(metaDataRegisterDTO.getRpcType()).register(metaDataRegisterDTO);
           }
       }
   }
   ```


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-shenyu] dengliming closed issue #1653: [refactor] Refactor code about different client register.

Posted by GitBox <gi...@apache.org>.
dengliming closed issue #1653:
URL: https://github.com/apache/incubator-shenyu/issues/1653


   


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org