Skip to content

Commit

Permalink
feat: consumer support specify serialization type (#9550)
Browse files Browse the repository at this point in the history
* consumer support specify serialization type

* xml support config consumer serialization

Co-authored-by: jessinguo <jessinguo@tencent.com>
  • Loading branch information
jessin20161124 and jessinguo committed Feb 6, 2022
1 parent 2341677 commit 2646c9d
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 14 deletions.
Expand Up @@ -16,14 +16,14 @@
*/
package org.apache.dubbo.config;

import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.support.Parameter;
import org.apache.dubbo.rpc.support.ProtocolUtils;

import static org.apache.dubbo.common.constants.CommonConstants.INVOKER_LISTENER_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.REFERENCE_FILTER_KEY;
import static org.apache.dubbo.common.constants.CommonConstants.STUB_EVENT_KEY;

import org.apache.dubbo.common.utils.StringUtils;
import org.apache.dubbo.config.support.Parameter;
import org.apache.dubbo.rpc.support.ProtocolUtils;

/**
* AbstractConsumerConfig
*
Expand Down Expand Up @@ -80,6 +80,11 @@ public abstract class AbstractReferenceConfig extends AbstractInterfaceConfig {

protected String router;

/**
* The serialization type
*/
protected String serialization;

public Boolean isCheck() {
return check;
}
Expand Down Expand Up @@ -223,4 +228,12 @@ public String getRouter() {
public void setRouter(String router) {
this.router = router;
}

public String getSerialization() {
return serialization;
}

public void setSerialization(String serialization) {
this.serialization = serialization;
}
}
Expand Up @@ -295,4 +295,10 @@
* @see RegistryConstants#PROVIDED_BY
*/
String[] providedBy() default {};

/**
* specify serialization from consumer side
* @see org.apache.dubbo.remoting.Constants#SERIALIZATION_KEY
*/
String serialization() default "";
}
Expand Up @@ -280,4 +280,10 @@
* @since 2.7.3
*/
String id() default "";

/**
* specify serialization from consumer side
* @see org.apache.dubbo.remoting.Constants#SERIALIZATION_KEY
*/
String serialization() default "";
}
Expand Up @@ -66,6 +66,11 @@ public abstract class AbstractReferenceBuilder<T extends AbstractReferenceConfig
*/
protected String group;

/**
* The serialization type
*/
protected String serialization;

public B check(Boolean check) {
this.check = check;
return getThis();
Expand Down Expand Up @@ -126,6 +131,11 @@ public B group(String group) {
return getThis();
}

public B serialization(String serialization) {
this.serialization = serialization;
return getThis();
}

@Override
public void build(T instance) {
super.build(instance);
Expand Down Expand Up @@ -157,5 +167,8 @@ public void build(T instance) {
if (!StringUtils.isEmpty(group)) {
instance.setGroup(group);
}
if (!StringUtils.isEmpty(serialization)) {
instance.setSerialization(serialization);
}
}
}
Expand Up @@ -244,6 +244,11 @@
<![CDATA[ The routers ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="serialization" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[ The serialization protocol of service. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
Expand Down
Expand Up @@ -245,6 +245,11 @@
<![CDATA[ The routers ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="serialization" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[ The serialization protocol of service. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
Expand Down
Expand Up @@ -17,11 +17,17 @@
package org.apache.dubbo.config.spring.beans.factory.annotation;


import static org.apache.dubbo.common.utils.CollectionUtils.ofSet;
import static org.springframework.core.annotation.AnnotationUtils.findAnnotation;
import static org.springframework.util.ReflectionUtils.findField;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.Reference;
import org.apache.dubbo.config.spring.ReferenceBean;
import org.apache.dubbo.rpc.model.ApplicationModel;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand All @@ -34,14 +40,6 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static org.apache.dubbo.common.utils.CollectionUtils.ofSet;
import static org.springframework.core.annotation.AnnotationUtils.findAnnotation;
import static org.springframework.util.ReflectionUtils.findField;

/**
* {@link ReferenceBeanBuilder} Test
*
Expand All @@ -59,7 +57,7 @@ public class ReferenceBeanBuilderTest {
interfaceClass = CharSequence.class,
interfaceName = "java.lang.CharSequence",
version = "1.0.0", group = "TEST_GROUP", url = "dubbo://localhost:12345",
client = "client", generic = true, injvm = true,
client = "client", generic = true, injvm = true, serialization = "fastjson",
check = false, init = false, lazy = true,
stubevent = true, reconnect = "reconnect", sticky = true,
proxy = "javassist", stub = "java.lang.CharSequence", cluster = "failover",
Expand Down Expand Up @@ -130,6 +128,7 @@ public void testBuild() throws Exception {
Assertions.assertEquals("reference", referenceBean.getId());
Assertions.assertEquals(ofSet("service1", "service2", "service3"), referenceBean.getSubscribedServices());
Assertions.assertEquals("service1,service2,service3", referenceBean.getProvidedBy());
Assertions.assertEquals("fastjson", referenceBean.getSerialization());

// parameters
Map<String, String> parameters = new HashMap<String, String>();
Expand Down

1 comment on commit 2646c9d

@ToryZhou
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你好,我现在用dubbo3.0.5遇到jodatime无法反序列化的问题,问下接下来支持哪些序列化方式,哪种方式支持jodatime的反序列化呢?

Please sign in to comment.