feat:DubboService annotation support custom serialization (#13553)
This commit is contained in:
parent
501a7a7653
commit
25b73b1a13
|
|
@ -257,7 +257,17 @@ public @interface DubboService {
|
|||
String[] listener() default {};
|
||||
|
||||
/**
|
||||
* Customized parameter key-value pair, for example: {key1, value1, key2, value2}
|
||||
* Customized parameter key-value pair, for example:
|
||||
* <pre>
|
||||
* ["a","b"] ==> {a=b}
|
||||
* [" a "," b "] ==> {a=b}
|
||||
* ["a=b"] ==>{a=b}
|
||||
* ["a:b"] ==>{a=b}
|
||||
* ["a=b","c","d"] ==>{a=b,c=d}
|
||||
* ["a","a:b"] ==>{a="a:b"}
|
||||
* ["a","a,b"] ==>{a="a,b"}
|
||||
* </pre>
|
||||
* @see org.apache.dubbo.config.spring.util.DubboAnnotationUtils#convertParameters(java.lang.String[])
|
||||
*/
|
||||
String[] parameters() default {};
|
||||
|
||||
|
|
@ -327,4 +337,21 @@ public @interface DubboService {
|
|||
* Payload max length.
|
||||
*/
|
||||
String payload() default "";
|
||||
|
||||
/**
|
||||
* The serialization type
|
||||
*/
|
||||
String serialization() default "";
|
||||
|
||||
/**
|
||||
* If the parameter has a value, the consumer will read the parameter first.
|
||||
* If the Dubbo Sdk you are using contains the serialization type, the serialization method specified by the argument is used.
|
||||
* <p>
|
||||
* When this parameter is null or the serialization type specified by this parameter does not exist in the Dubbo SDK, the serialization type specified by serialization is used.
|
||||
* If the Dubbo SDK if still does not exist, the default type of the Dubbo SDK is used.
|
||||
* For Dubbo SDK >= 3.2, <code>preferSerialization</code> takes precedence over <code>serialization</code>
|
||||
* <p>
|
||||
* The configuration supports multiple, which are separated by commas.Such as:<code>fastjson2,fastjson,hessian2</code>
|
||||
*/
|
||||
String preferSerialization() default "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -135,6 +135,13 @@
|
|||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-serialization-jdk</artifactId>
|
||||
<version>${project.parent.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-registry-multicast</artifactId>
|
||||
|
|
|
|||
|
|
@ -132,6 +132,7 @@ import static org.apache.dubbo.remoting.Constants.CLIENT_KEY;
|
|||
import static org.apache.dubbo.remoting.Constants.CODEC_KEY;
|
||||
import static org.apache.dubbo.remoting.Constants.DISPATCHER_KEY;
|
||||
import static org.apache.dubbo.remoting.Constants.EXCHANGER_KEY;
|
||||
import static org.apache.dubbo.remoting.Constants.PREFER_SERIALIZATION_KEY;
|
||||
import static org.apache.dubbo.remoting.Constants.SERIALIZATION_KEY;
|
||||
import static org.apache.dubbo.remoting.Constants.SERVER_KEY;
|
||||
import static org.apache.dubbo.remoting.Constants.TELNET_KEY;
|
||||
|
|
@ -602,6 +603,11 @@ public class ConfigValidationUtils {
|
|||
checkMultiExtension(config.getScopeModel(), Codec2.class, CODEC_KEY, config.getCodec());
|
||||
checkMultiExtension(
|
||||
config.getScopeModel(), Serialization.class, SERIALIZATION_KEY, config.getSerialization());
|
||||
checkMultiExtension(
|
||||
config.getScopeModel(),
|
||||
Serialization.class,
|
||||
PREFER_SERIALIZATION_KEY,
|
||||
config.getPreferSerialization());
|
||||
checkMultiExtension(config.getScopeModel(), Transporter.class, SERVER_KEY, config.getServer());
|
||||
checkMultiExtension(config.getScopeModel(), Transporter.class, CLIENT_KEY, config.getClient());
|
||||
}
|
||||
|
|
@ -623,6 +629,9 @@ public class ConfigValidationUtils {
|
|||
checkMultiExtension(config.getScopeModel(), StatusChecker.class, STATUS_KEY, config.getStatus());
|
||||
checkExtension(config.getScopeModel(), Transporter.class, TRANSPORTER_KEY, config.getTransporter());
|
||||
checkExtension(config.getScopeModel(), Exchanger.class, EXCHANGER_KEY, config.getExchanger());
|
||||
checkMultiExtension(config.getScopeModel(), Serialization.class, SERIALIZATION_KEY, config.getSerialization());
|
||||
checkMultiExtension(
|
||||
config.getScopeModel(), Serialization.class, PREFER_SERIALIZATION_KEY, config.getPreferSerialization());
|
||||
}
|
||||
|
||||
public static void validateConsumerConfig(ConsumerConfig config) {
|
||||
|
|
|
|||
|
|
@ -70,6 +70,31 @@ class AbstractConfigTest {
|
|||
ConfigValidationUtils.validateProtocolConfig(protocolConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testValidateProtocolConfigSerialization() {
|
||||
ProtocolConfig protocolConfig = new ProtocolConfig();
|
||||
protocolConfig.setCodec("exchange");
|
||||
protocolConfig.setName("dubbo");
|
||||
protocolConfig.setHost("host");
|
||||
protocolConfig.setSerialization("fastjson2");
|
||||
protocolConfig.setPreferSerialization("hessian2,java,compactedjava,nativejava");
|
||||
ConfigValidationUtils.validateProtocolConfig(protocolConfig);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testValidateProtocolConfigViolateSerialization() {
|
||||
|
||||
Assertions.assertThrowsExactly(IllegalStateException.class, () -> {
|
||||
ProtocolConfig protocolConfig = new ProtocolConfig();
|
||||
protocolConfig.setCodec("exchange");
|
||||
protocolConfig.setName("dubbo");
|
||||
protocolConfig.setHost("host");
|
||||
protocolConfig.setSerialization("violate");
|
||||
protocolConfig.setPreferSerialization("violate");
|
||||
ConfigValidationUtils.validateProtocolConfig(protocolConfig);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAppendParameters1() {
|
||||
Map<String, String> parameters = new HashMap<String, String>();
|
||||
|
|
|
|||
|
|
@ -316,21 +316,6 @@ class DubboBootstrapTest {
|
|||
registryConfig.setUseAsMetadataCenter(false);
|
||||
registryConfig.setUseAsConfigCenter(false);
|
||||
|
||||
Exception exception = null;
|
||||
try {
|
||||
DubboBootstrap.getInstance()
|
||||
.application(applicationConfig)
|
||||
.registry(registryConfig)
|
||||
.protocol(new ProtocolConfig(CommonConstants.DUBBO_PROTOCOL, -1))
|
||||
.service(service)
|
||||
.start();
|
||||
} catch (Exception e) {
|
||||
exception = e;
|
||||
DubboBootstrap.reset();
|
||||
}
|
||||
|
||||
Assertions.assertNotNull(exception);
|
||||
|
||||
DubboBootstrap.getInstance()
|
||||
.application(applicationConfig)
|
||||
.registry(registryConfig)
|
||||
|
|
@ -342,6 +327,33 @@ class DubboBootstrapTest {
|
|||
assertMetadataService(DubboBootstrap.getInstance(), availablePort, false);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRemoteMetadataServiceExporterCheckMetadataType() {
|
||||
|
||||
Assertions.assertThrowsExactly(IllegalStateException.class, () -> {
|
||||
ServiceConfig<DemoService> service = new ServiceConfig<>();
|
||||
service.setInterface(DemoService.class);
|
||||
service.setRef(new DemoServiceImpl());
|
||||
|
||||
int availablePort = NetUtils.getAvailablePort();
|
||||
|
||||
ApplicationConfig applicationConfig = new ApplicationConfig("bootstrap-test");
|
||||
applicationConfig.setMetadataServicePort(availablePort);
|
||||
applicationConfig.setMetadataType(REMOTE_METADATA_STORAGE_TYPE);
|
||||
|
||||
RegistryConfig registryConfig = new RegistryConfig(zkServerAddress);
|
||||
registryConfig.setUseAsMetadataCenter(false);
|
||||
registryConfig.setUseAsConfigCenter(false);
|
||||
|
||||
DubboBootstrap.getInstance()
|
||||
.application(applicationConfig)
|
||||
.registry(registryConfig)
|
||||
.protocol(new ProtocolConfig(CommonConstants.DUBBO_PROTOCOL, -1))
|
||||
.service(service)
|
||||
.start();
|
||||
});
|
||||
}
|
||||
|
||||
private ExporterDeployListener getListener(ApplicationModel model) {
|
||||
return (ExporterDeployListener)
|
||||
model.getExtensionLoader(ApplicationDeployListener.class).getExtension("exporter");
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ public class DubboAnnotationUtils {
|
|||
* be split in anytime.It will throw IllegalArgumentException If converted array length isn't
|
||||
* even number.
|
||||
* The convert cases below work in right way,which are best practice.
|
||||
* <p>
|
||||
* <pre>
|
||||
* (array->map)
|
||||
* ["a","b"] ==> {a=b}
|
||||
* [" a "," b "] ==> {a=b}
|
||||
|
|
@ -147,7 +147,7 @@ public class DubboAnnotationUtils {
|
|||
* ["a=b","c","d"] ==>{a=b,c=d}
|
||||
* ["a","a:b"] ==>{a="a:b"}
|
||||
* ["a","a,b"] ==>{a="a,b"}
|
||||
* </p>
|
||||
* </pre>
|
||||
*
|
||||
* @param parameters
|
||||
* @return
|
||||
|
|
|
|||
Loading…
Reference in New Issue