-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: 添加就近路由支持文档 * rebase upstream/master * fix:修复demo中缺失import问题 * fix:修复demo中缺失import问题 * feat:suppport watch services change event
- Loading branch information
1 parent
a0389ad
commit 0e788fb
Showing
17 changed files
with
421 additions
and
28 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
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
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
examples/watch/longpull/polaris.yaml → ...ples/watch/instance/longpull/polaris.yaml
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
global: | ||
serverConnector: | ||
addresses: | ||
- 9.134.5.52:8091 | ||
- 127.0.0.1:8091 | ||
statReporter: | ||
enable: false | ||
enable: false |
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
4 changes: 2 additions & 2 deletions
4
examples/watch/notify/polaris.yaml → examples/watch/instance/notify/polaris.yaml
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
global: | ||
serverConnector: | ||
addresses: | ||
- 9.134.5.52:8091 | ||
- 127.0.0.1:8091 | ||
statReporter: | ||
enable: false | ||
enable: false |
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,73 @@ | ||
/** | ||
* Tencent is pleased to support the open source community by making Polaris available. | ||
* | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* Licensed under the BSD 3-Clause License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed | ||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"time" | ||
|
||
"github.com/polarismesh/polaris-go" | ||
"github.com/polarismesh/polaris-go/api" | ||
) | ||
|
||
var ( | ||
namespace string | ||
waitIndex uint64 | ||
waitTime time.Duration | ||
) | ||
|
||
func initArgs() { | ||
flag.StringVar(&namespace, "namespace", "", "namespace") | ||
flag.Uint64Var(&waitIndex, "waitIndex", 0, "waitIndex") | ||
flag.DurationVar(&waitTime, "waitTime", 60*time.Second, "waitTime") | ||
} | ||
|
||
func main() { | ||
initArgs() | ||
flag.Parse() | ||
consumer, err := polaris.NewConsumerAPI() | ||
if err != nil { | ||
log.Fatalf("fail to create consumerAPI, err is %v", err) | ||
} | ||
defer consumer.Destroy() | ||
|
||
var index uint64 = waitIndex | ||
|
||
for { | ||
req := &polaris.WatchAllServicesRequest{} | ||
req.Namespace = namespace | ||
req.WaitTime = waitTime | ||
req.WaitIndex = index | ||
req.WatchMode = api.WatchModeLongPull | ||
resp, err := consumer.WatchAllServices(req) | ||
if err != nil { | ||
log.Fatalf("fail to watch all instances, namespace %s, err: %s", namespace, err) | ||
} | ||
servicesResp := resp.ServicesResponse() | ||
index = servicesResp.GetHashValue() | ||
log.Printf("namespace %s, services count is %d, revision : %s, next watch index %d", namespace, | ||
len(servicesResp.GetValue()), resp.ServicesResponse().GetRevision(), index) | ||
// for _, svc := range servicesResp.GetValue() { | ||
// log.Printf("namespace %s, svc %s", svc.Namespace, svc.Service) | ||
// } | ||
|
||
log.Printf("namespace %s, watch id is %d\n", namespace, resp.WatchId()) | ||
resp.CancelWatch() | ||
} | ||
} |
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,6 @@ | ||
global: | ||
serverConnector: | ||
addresses: | ||
- 127.0.0.1:8091 | ||
statReporter: | ||
enable: false |
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,84 @@ | ||
/** | ||
* Tencent is pleased to support the open source community by making Polaris available. | ||
* | ||
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. | ||
* | ||
* Licensed under the BSD 3-Clause License (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://opensource.org/licenses/BSD-3-Clause | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed | ||
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
* CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"sync" | ||
|
||
"github.com/polarismesh/polaris-go" | ||
"github.com/polarismesh/polaris-go/api" | ||
"github.com/polarismesh/polaris-go/pkg/model" | ||
) | ||
|
||
var ( | ||
namespace string | ||
waitIndex uint64 | ||
) | ||
|
||
func initArgs() { | ||
flag.StringVar(&namespace, "namespace", "Polaris", "namespace") | ||
flag.Uint64Var(&waitIndex, "waitIndex", 0, "waitIndex") | ||
} | ||
|
||
const svcCount = 1 | ||
|
||
var port int32 = 1000 | ||
|
||
type TestListener struct { | ||
wg *sync.WaitGroup | ||
} | ||
|
||
// OnInstancesUpdate notify when service instances changed | ||
func (t *TestListener) OnServicesUpdate(resp *model.ServicesResponse) { | ||
defer t.wg.Done() | ||
log.Printf("receive namespace %s, services change, new count is %d, revision : %s", namespace, len(resp.GetValue()), resp.GetRevision()) | ||
// for _, svc := range resp.GetValue() { | ||
// log.Printf("namespace %s, svc %s", svc.Namespace, svc.Service) | ||
// } | ||
} | ||
|
||
func main() { | ||
initArgs() | ||
flag.Parse() | ||
consumer, err := polaris.NewConsumerAPI() | ||
if err != nil { | ||
log.Fatalf("fail to create consumerAPI, err is %v", err) | ||
} | ||
defer consumer.Destroy() | ||
|
||
wg := &sync.WaitGroup{} | ||
wg.Add(10) | ||
req := &polaris.WatchAllServicesRequest{} | ||
req.Namespace = namespace | ||
req.WatchMode = api.WatchModeNotify | ||
req.ServicesListener = &TestListener{ | ||
wg: wg, | ||
} | ||
resp, err := consumer.WatchAllServices(req) | ||
if err != nil { | ||
log.Fatalf("fail to watch all services, namespace %s, err: %s", namespace, err) | ||
} | ||
servicesResp := resp.ServicesResponse() | ||
log.Printf("namespace %s, services count is %d", namespace, len(servicesResp.GetValue())) | ||
// for _, svc := range servicesResp.GetValue() { | ||
// log.Printf("namespace %s, svc %s", svc.Namespace, svc.Service) | ||
// } | ||
wg.Wait() | ||
} |
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,6 @@ | ||
global: | ||
serverConnector: | ||
addresses: | ||
- 127.0.0.1:8091 | ||
statReporter: | ||
enable: false |
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
Oops, something went wrong.