Redis Registry Server
Redis Registry Server
It is a registry server implementation 1 based on redis 2.
Use key/map structure in redis to save the registration info:
- Main key for service name and type
- Key in the map is URL address
- Value in the map is the expiration time. Monitor center uses it to track and remove dirty data 3
Publish/Subscribe events in redis is leveraged for data change notification:
- Distinguish event type with event’s value:
register
,unregister
,subscribe
,unsubscribe
. - Regular subscriber subscribes the particular key presenting service provider, then will receive
register
andunregister
events fired from the specified service. - Monitor center subscribes
/dubbo/*
viapsubscribe
, then will receive all change notifications from all services.
Procedure:
- When service provider boots up, it adds its address under
Key:/dubbo/com.foo.BarService/providers
. - Then service provider sends
register
event toChannel:/dubbo/com.foo.BarService/providers
- When service consumer boots up, it subscribe events
register
andunregister
fromChannel:/dubbo/com.foo.BarService/providers
- Then service consumer add its address under
Key:/dubbo/com.foo.BarService/consumers
- When service consumer receives events
register
andunregister
, it will fetch provider’s addresses fromKey:/dubbo/com.foo.BarService/providers
- When monitor center boots up, it subscribes events
register
,unregister
,subscribe
, andunsubsribe
. - After monitor center receives
register
andunregister
, it fetches provider’s addresses fromKey:/dubbo/com.foo.BarService/providers
- After monitor center receives
subscribe
andunsubscribe
, it fetches consumer’s addresses fromKey:/dubbo/com.foo.BarService/consumers
Configuration
<dubbo:registry address="redis://10.20.153.10:6379" />
Or
<dubbo:registry address="redis://10.20.153.10:6379?backup=10.20.153.11:6379,10.20.153.12:6379" />
Or
<dubbo:registry protocol="redis" address="10.20.153.10:6379" />
Or
<dubbo:registry protocol="redis" address="10.20.153.10:6379,10.20.153.11:6379,10.20.153.12:6379" />
Options
- Config key’s prefix in redis via
<dubbo:registry group="dubbo" />
, the default value isdubbo
. - Config redis cluster strategy via
<dubbo:registry cluster="replicate" />
, the default value isfailover
:failover
: when read/write error happens, try another instance, require the cluster to support data replication.replicate
: client writes to all nodes of the cluster, but only peeks a random node for read. The cluster doesn’t need to take care of data replication, but may require more nodes and higher performance for each node, compared to option 1.
Declaration of Reliability
A home-brewed service registry server is used in Alibaba instead of redis server. Redis based registry center does not have long-run practice within Alibaba, therefore we cannot guarantee its reliability. This registry server implementation is provided for dubbo community, and its reliability relies on redis itself largely.
Installation
Pls. refer to redis install manual for how to install a redis based registry server. To set it up, specify dubbo.registry.address
to redis://127.0.0.1:6379
in conf/dubbo.properties
for both provider and consumer (you can refer to quick start) after install a redis server.