-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add retry feature for etcd (#91)
* feat: add retry feature for etcd * use sonic * update * add unit test * add unit test
- Loading branch information
1 parent
cab5b29
commit eb24a62
Showing
7 changed files
with
307 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
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,51 @@ | ||
// Copyright 2021 CloudWeGo Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// 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 ( | ||
"context" | ||
"time" | ||
|
||
"github.com/cloudwego/hertz/pkg/app" | ||
"github.com/cloudwego/hertz/pkg/app/server" | ||
"github.com/cloudwego/hertz/pkg/app/server/registry" | ||
"github.com/cloudwego/hertz/pkg/common/utils" | ||
"github.com/cloudwego/hertz/pkg/protocol/consts" | ||
"github.com/hertz-contrib/registry/etcd" | ||
) | ||
|
||
func main() { | ||
r, _ := etcd.NewEtcdRegistry( | ||
[]string{"127.0.0.1:2379"}, | ||
etcd.WithMaxAttemptTimes(10), | ||
etcd.WithObserveDelay(20*time.Second), | ||
etcd.WithRetryDelay(5*time.Second), | ||
) | ||
|
||
addr := "127.0.0.1:8888" | ||
h := server.Default( | ||
server.WithHostPorts(addr), | ||
server.WithRegistry(r, ®istry.Info{ | ||
ServiceName: "hertz.test.demo", | ||
Addr: utils.NewNetAddr("tcp", addr), | ||
Weight: 10, | ||
Tags: nil, | ||
}), | ||
) | ||
h.GET("/ping", func(_ context.Context, ctx *app.RequestContext) { | ||
ctx.JSON(consts.StatusOK, utils.H{"ping": "pong2"}) | ||
}) | ||
h.Spin() | ||
} |
File renamed without changes.
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
Oops, something went wrong.