apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.
https://dubbo.apache.org/
Apache License 2.0
40.41k stars 26.41k forks source link

Can provider support multi serialization protocols? #5180

Open RojerAlone opened 4 years ago

RojerAlone commented 4 years ago

I'm trying to change my service's serialization protocol gracefully, so I want to implement a feature like this:

provider can support multi serialization protocols, and consumer assigns its serialization protocol, provider can receive consumer's request correctlly if consumer's serialization protocol is supported by provider.

I found there's a issue #4640 related my problem, and known that the consumer can't assign self serizalization protocol.

I try to set the dubbo.protocol.serialization = protostuff,fastjson in the application.yml, the provider service can start up successfully and the registry url contains serialization field, but when I send request to the provider, I got an exception No such extension org.apache.dubbo.common.serialize.Serialization by name protostuff,fastjson, it seems provider can't support multi serialization protocols, but why the code shows it seems it supports?

Am I using it wrong?

And more, I think it's not graceful enough that consumer can't assign self serialization protocol, can you introduce to me why design it like this?

zyna commented 4 years ago

I think it not support. The code just check the serialization attribute validity.when consumer invoking provider,the source code has no parsing serialization attribute.

RojerAlone commented 4 years ago

@zyna If the serialization protocol is only supported one, then the setSerialization method does't need to check if serialization is multi extension:

    public void setSerialization(String serialization) {
        if (DUBBO_PROTOCOL.equals(name)) {
            checkMultiExtension(Serialization.class, Constants.SERIALIZATION_KEY, serialization);
        }
        this.serialization = serialization;
    }
zyna commented 4 years ago

@RojerAlone Yes, I think checkMultiExtension method is not necessary,can use checkExtension method to replace it.

RojerAlone commented 4 years ago

Beside this, I think consumer can choose serialization protocol by itself rather than dependency on provider's registry url, or consumer throws an exception when the serialization protocol is unsupported by provider, it's ok in logic.

zyna commented 4 years ago

you can try like this.

RojerAlone commented 4 years ago

you can try like this.

Is this configuratiton indicates the provider supports multi protocol? so how consumers choose which to use. I use spring boot, it seems to unsupport multi protocol field in the yml file.