Skip to content

Commit

Permalink
Fix retry mechanism in rest clients
Browse files Browse the repository at this point in the history
  • Loading branch information
levichevdmitry committed Aug 30, 2021
1 parent 7b56e42 commit 87a4ae5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# <img src="https://uploads-ssl.webflow.com/5ea5d3315186cf5ec60c3ee4/5edf1c94ce4c859f2b188094_logo.svg" alt="Pip.Services Logo" width="200"> <br/> Remote Procedure Calls for Pip.Services in Go Changelog

## <a name="1.4.4"></a> 1.4.4 (2021-08-30)
### Bug fixing
* Fix retry mechnaism in REST client

## <a name="1.4.3"></a> 1.4.3 (2021-08-23)
### Bug fixing
Expand Down
33 changes: 16 additions & 17 deletions clients/RestClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ func (c *RestClient) Call(prototype reflect.Type, method string, route string, c
if params.Len() > 0 {
route += "?"
for k, v := range params.Value() {
//route += neturl.QueryEscape(k) + "=" + neturl.QueryEscape(v) + "&"
route += neturl.QueryEscape(k) + "=" + neturl.QueryEscape(v) + "&"
}
if strings.HasSuffix(route, "&") {
Expand All @@ -356,29 +355,29 @@ func (c *RestClient) Call(prototype reflect.Type, method string, route string, c
if data != nil {
jsonStr, _ = json.Marshal(data)
} else {
jsonStr = make([]byte, 0, 0)
}
req, reqErr := http.NewRequest(method, url, bytes.NewBuffer(jsonStr))

if reqErr != nil {
err = cerr.NewUnknownError(correlationId, "UNSUPPORTED_METHOD", "Method is not supported by REST client").WithDetails("verb", method).WithCause(reqErr)
return nil, err
}
// Set headers
req.Header.Set("Content-Type", "application/json")
if c.passCorrelationId == "headers" || c.passCorrelationId == "both" {
req.Header.Set("correlation_id", correlationId)
}
//req.Header.Set("User-Agent", c.UserAgent)
for k, v := range c.Headers.Value() {
req.Header.Set(k, v)
jsonStr = make([]byte, 0)
}

retries := c.Retries
var resp *http.Response
var respErr error

for retries > 0 {
req, reqErr := http.NewRequest(method, url, bytes.NewBuffer(jsonStr))

if reqErr != nil {
err = cerr.NewUnknownError(correlationId, "UNSUPPORTED_METHOD", "Method is not supported by REST client").WithDetails("verb", method).WithCause(reqErr)
return nil, err
}
// Set headers
req.Header.Set("Content-Type", "application/json")
if c.passCorrelationId == "headers" || c.passCorrelationId == "both" {
req.Header.Set("correlation_id", correlationId)
}
//req.Header.Set("User-Agent", c.UserAgent)
for k, v := range c.Headers.Value() {
req.Header.Set(k, v)
}
// Try send request
resp, respErr = c.Client.Do(req)
if respErr != nil {
Expand Down
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pip-services3-rpc-go",
"registry": "github.com/pip-services3-go",
"version": "1.4.3",
"version": "1.4.4",
"build": 0
}

0 comments on commit 87a4ae5

Please sign in to comment.