You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/10/22 06:02:59 UTC

[GitHub] [dubbo-spi-extensions] gcdd1993 opened a new issue #78: Kryo序列化协议,希望能加入自定义注册类的ClassId的支持

gcdd1993 opened a new issue #78:
URL: https://github.com/apache/dubbo-spi-extensions/issues/78


   - [x] I have searched the [issues](https://github.com/apache/dubbo/issues) of this repository and believe that this is not a duplicate.
   - [x] I have checked the [FAQ](https://github.com/apache/dubbo/blob/master/FAQ.md) of this repository and believe that this is not a duplicate.
   
   ### Environment
   
   * Dubbo version: 2.7.8
   * Operating System version: Win10
   * Java version: Jdk11
   
   ### 场景描述
   在多模块协作的系统中,无法保证服务提供方和消费方Java DTO数量以及注册顺序的一致,可能A作为服务提供方,提供了DTO,而B作为消费方,可能同时消费A、C的服务,同时自身也对外提供服务,在使用Kryo序列化时,需要同时注册A、B、C服务的DTO。
   
   例如A系统的SerializationOptimizer实现
   
   ```java
   public class ASerializationOptimizerImpl
           implements SerializationOptimizer {
       @Override
       public Collection<Class<?>> getSerializableClasses() {
           return A1.class;
           return A2.class;
           return A3.class;
           return A4.class;
           return C1.class;
           return C2.class;
       }
   }
   ```
   
   B系统的SerializationOptimizer实现
   
   ```java
   public class BSerializationOptimizerImpl
           implements SerializationOptimizer {
       @Override
       public Collection<Class<?>> getSerializableClasses() {
           return A1.class;
           return A2.class;
           return A3.class;
           return A4.class;
           return B1.class;
           return B2.class;
           return C1.class;
           return C2.class;
       }
   }
   ```
   
   目前Dubbo使用的主要是Kryo的
   ```java
   public Registration register (Class type) {
   	Registration registration = classResolver.getRegistration(type);
   	if (registration != null) return registration;
   	return register(type, getDefaultSerializer(type));
   }
   ```
   该方法的实现,要求**反序列化时的顺序必须与序列化时的顺序相同**。
   在多模块系统下很难达成此条件。
   
   希望能加入对`com.esotericsoftware.kryo.Kryo#register (Class type, int id)`的支持,自定义ClassId
   ```java
   public Registration register (Class type, int id) {
   	Registration registration = classResolver.getRegistration(type);
   	if (registration != null) return registration;
   	return register(type, getDefaultSerializer(type), id);
   }
   ```
   
   
   


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

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

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



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org