apache / dubbo

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

About the practice in multiple registries using dubbo.properties #5204

Closed jasonjoo2010 closed 3 years ago

jasonjoo2010 commented 5 years ago

Environment

Scenario

We have an interface provided in two IDC clusters. We call them BJ / HZ. The target interface we call it AService.

In project AProject we want to subscribe AService separately from both BJ and HZ for different beans' registering.

In XML age we can easily achieving that by

<dubbo:registry id="ARegistry" address="xxx" />
<dubbo:registry id="BRegistry" address="zzz" register="false" />
<dubbo:consumer registry="ARegistry" .... />
<dubbo:consumer interface="AService" id="beanA />
<dubbo:consumer interface="AService" id="beanB" registry="BRegistry />

But in dubbo.properties, it's hard and the correct way is:

# main registry
dubbo.registry.id=registryMain
dubbo.registry.address=xxxx
dubbo.registry.file=logs/dubbo-registry-main.properties
dubbo.registry.protocol=zookeeper

# second registry
dubbo.registries.registryOther.id=registryOther
dubbo.registries.registryOther.address=zzzz
dubbo.registries.registryOther.file=logs/dubbo-registry-other.properties
dubbo.registries.registryOther.protocol=zookeeper
dubbo.registries.registryOther.register=false

dubbo.provider.timeout=30000
dubbo.provider.registryIds=registryMain

dubbo.consumer.id=consumerMain
dubbo.consumer.registryIds=registryMain
dubbo.consumer.timeout=30000
dubbo.consumer.retries=0
dubbo.consumer.default=true           ########## important

dubbo.consumers.consumerOther.id=consumerOther
dubbo.consumers.consumerOther.registryIds=registryOther
dubbo.consumers.consumerOther.timeout=30000
dubbo.consumers.consumerOther.retries=0
dubbo.consumers.consumerOther.default=false         ####### important

dubbo.monitor.protocol=registry

And when reference:

@Reference
private AService beanA;
@Reference(consumer = "consumerOther", injvm = false, id = "beanB")
private AService beanB;

Following will not achieve it:

# main registry
dubbo.registry.id=registryMain
dubbo.registry.address=xxxx
dubbo.registry.file=logs/dubbo-registry-main.properties
dubbo.registry.protocol=zookeeper
dubbo.registry.default=true     #########

# second registry
dubbo.registries.registryOther.id=registryOther
dubbo.registries.registryOther.address=zzzz
dubbo.registries.registryOther.file=logs/dubbo-registry-other.properties
dubbo.registries.registryOther.protocol=zookeeper
dubbo.registries.registryOther.register=false
dubbo.registries.registryOther.default=false

dubbo.provider.timeout=30000
dubbo.provider.registryIds=registryMain

dubbo.consumer.id=consumerMain
dubbo.consumer.registryIds=registryMain
dubbo.consumer.timeout=30000
dubbo.consumer.retries=0

dubbo.monitor.protocol=registry
@Reference
private AService beanA;
@Reference(registry = "registryOther", injvm = false, id = "beanB")
private AService beanB;

Will cause unexpected subscription and wrong configuration for beanB.

And setting registryOther both register=false and subscript=false will ignore its initializing.

Same to other kinds of such configuration combinations.

Is that an issue?

CrazyHZM commented 3 years ago

Try it with the latest version, if you still have problems, you can reopen the issues