Skip to content

Commit

Permalink
Merge pull request #5 from xianlezheng/feature/etcd-service-discovery
Browse files Browse the repository at this point in the history
Feature/etcd service discovery
  • Loading branch information
flycash authored Jun 23, 2020
2 parents facab2b + 5aaee6d commit be56ab1
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
5 changes: 2 additions & 3 deletions registry/etcdv3/service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,12 @@ func (e *etcdV3ServiceDiscovery) Register(instance registry.ServiceInstance) err
if nil != e.client {
ins, err := jsonutil.EncodeJSON(instance)
if err == nil {
err = e.client.Update(path, string(ins))
err = e.client.RegisterTemp(path, string(ins))
if err != nil {
logger.Errorf("cannot register the instance: %s", string(ins), err)
} else {
e.services.Add(instance.GetServiceName())
}

}
}

Expand All @@ -109,7 +108,7 @@ func (e *etcdV3ServiceDiscovery) Update(instance registry.ServiceInstance) error
if nil != e.client {
ins, err := jsonutil.EncodeJSON(instance)
if nil == err {
e.client.Update(path, string(ins))
e.client.RegisterTemp(path, string(ins))
e.services.Add(instance.GetServiceName())
}
}
Expand Down
11 changes: 4 additions & 7 deletions remoting/etcdv3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package etcdv3

import (
"context"
"path"
"sync"
"time"
)
Expand Down Expand Up @@ -520,16 +519,14 @@ func (c *Client) Delete(k string) error {
}

// RegisterTemp registers a temporary node
func (c *Client) RegisterTemp(basePath string, node string) (string, error) {
func (c *Client) RegisterTemp(k, v string) error {

completeKey := path.Join(basePath, node)

err := c.keepAliveKV(completeKey, "")
err := c.keepAliveKV(k, v)
if err != nil {
return "", perrors.WithMessagef(err, "keepalive kv (key %s)", completeKey)
return perrors.WithMessagef(err, "keepalive kv (key %s)", k)
}

return completeKey, nil
return nil
}

// GetChildrenKVList gets children kv list by @k
Expand Down
2 changes: 1 addition & 1 deletion remoting/etcdv3/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ func (suite *ClientTestSuite) TestClientRegisterTemp() {
assert.Contains(t, events, eDelete)
}()

_, err := c.RegisterTemp("scott", "wang")
err := c.RegisterTemp("scott/wang", "test")
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit be56ab1

Please sign in to comment.