-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9620 from kobergj/FixNatsjsRegistry
Repair Natsjskv Registry
- Loading branch information
Showing
7 changed files
with
151 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Bugfix: Repair nats-js-kv registry | ||
|
||
The registry would always send traffic to only one pod. This is now fixed and load should be spread evenly. Also implements watcher method so the cache can use it. | ||
|
||
https://github.com/owncloud/ocis/pull/9620 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package natsjsregistry | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/nats-io/nats.go" | ||
"go-micro.dev/v4/registry" | ||
) | ||
|
||
// NatsWatcher is the watcher of the nats interface | ||
type NatsWatcher interface { | ||
WatchAll(bucket string, opts ...nats.WatchOpt) (nats.KeyWatcher, error) | ||
} | ||
|
||
// Watcher is used to keep track of changes in the registry | ||
type Watcher struct { | ||
watch nats.KeyWatcher | ||
updates <-chan nats.KeyValueEntry | ||
reg *storeregistry | ||
} | ||
|
||
// NewWatcher returns a new watcher | ||
func NewWatcher(s *storeregistry) (*Watcher, error) { | ||
w, ok := s.store.(NatsWatcher) | ||
if !ok { | ||
return nil, errors.New("store does not implement watcher interface") | ||
} | ||
|
||
watcher, err := w.WatchAll("service-registry") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &Watcher{ | ||
watch: watcher, | ||
updates: watcher.Updates(), | ||
reg: s, | ||
}, nil | ||
} | ||
|
||
// Next returns the next result. It is a blocking call | ||
func (w *Watcher) Next() (*registry.Result, error) { | ||
kve := <-w.updates | ||
if kve == nil { | ||
return nil, errors.New("watcher stopped") | ||
} | ||
|
||
service, err := w.reg.getService(kve.Key()) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var action string | ||
switch kve.Operation() { | ||
default: | ||
action = "create" | ||
case nats.KeyValuePut: | ||
action = "create" | ||
case nats.KeyValueDelete: | ||
action = "delete" | ||
case nats.KeyValuePurge: | ||
action = "delete" | ||
} | ||
|
||
return ®istry.Result{ | ||
Service: service, | ||
Action: action, | ||
}, nil | ||
} | ||
|
||
// Stop stops the watcher | ||
func (w *Watcher) Stop() { | ||
_ = w.watch.Stop() | ||
} |
16 changes: 15 additions & 1 deletion
16
vendor/github.com/go-micro/plugins/v4/store/nats-js-kv/nats.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters