Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: consumer support specify serialization type #9550

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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