Service Registration and Discovery

Service Registration and Discovery Extensions provided by Hertz.

The service discovery extensions currently supported in the open source version of Hertz are stored in the registry. You are welcomed to join us in contributing and maintaining for this project.

As of now, the supported service discovery extensions are

Configurations

Some optional configurations are provided to users when using service discovery.

Configuration Description
WithSD Used in conjunction with service discovery, this request uses service discovery when true is passed.
WithTag Used in conjunction with service discovery to set Tag information.
WithCustomizedAddrs Customize the address of the target instance.
WithLoadBalanceOptions Configure load balancing options.

WithSD

The WithSD configuration item is provided, and when the parameter is passed as true, this request uses service discovery. The WithSD configuration item must be used when using service discovery requests. Signature:

func WithSD(b bool) RequestOption

Sample code:

status, body, err := cli.Get(context.Background(), nil, "http://hertz.test.demo/ping", config.WithSD(true))

WithTag

Provides the WithTag configuration, which is used to set the Tag information. Signature:

func WithTag(k, v string) RequestOption

Sample code:

status, body, err := cli.Get(context.Background(), nil, "http://hertz.test.demo/ping", config.WithTag("foo", "var"))

WithCustomizedAddrs

This configuration item specifies the target instance address during service discovery. It will overwrite the result from Resolver. Resolver is a service discovery center for service discovery.

Signature:

func WithCustomizedAddrs(addrs ...string) ServiceDiscoveryOption

Sample code:

cli.Use(sd.Discovery(r, sd.WithCustomizedAddrs("127.0.0.1:8088")))

WithLoadBalanceOptions

This configuration item can configure the load balancing algorithm and load balancing parameters for the client.

Signature:

func WithLoadBalanceOptions(lb loadbalance.Loadbalancer, options loadbalance.Options) ServiceDiscoveryOption

Sample code:

cli.Use(sd.Discovery(r, sd.WithLoadBalanceOptions(loadbalance.NewWeightedBalancer(), loadbalance.Options{
     RefreshInterval: 5 * time. Second,
     ExpireInterval: 15 * time. Second,
})))

Custom load-balance extensions are detailed in Load Balancing Extensions.


nacos

Service Registration and Discovery nacos Extensions provided by Hertz.

consul

Service Registration and Discovery consul Extensions provided by Hertz.

etcd

Service Registration and Discovery etcd Extensions provided by Hertz.

eureka

Service Registration and Discovery eureka Extensions provided by Hertz.

polaris

Service Registration and Discovery polaris Extensions provided by Hertz.

servicecomb

Service Registration and Discovery servicecomb Extensions provided by Hertz.

zookeeper

Service Registration and Discovery zookeeper Extensions provided by Hertz.

redis

Service Registration and Discovery redis Extensions provided by Hertz.


Last modified July 24, 2024 : docs: fix error in render (#1110) (34e4f87)