Open qiluge opened 5 years ago
and my monitor program run with rippled sync node at same machine.
the original response of server is Service Unavailable
of error invalid character 'S' looking for beginning of value
Could you give an example of how your monitoring program calls the server e.g. via curl
?
func GetHeight(restClient *utils.RestClient, url string) (uint32, error) {
req := &rpcReq{
Method: "ledger_closed",
}
reqData, err := json.Marshal(req)
if err != nil {
return 0, fmt.Errorf("GetHeight: marshal req err: %s", err)
}
respData, err := restClient.SendRestRequest(url, reqData)
if err != nil {
return 0, fmt.Errorf("GetHeight: send req err: %s", err)
}
resp := &heightResp{}
err = json.Unmarshal(respData, resp)
if err != nil {
return 0, fmt.Errorf("GetHeight, unmarshal resp err: %s, origin resp is %s", err, string(respData))
}
if resp.Result.Status != "success" {
return 0, fmt.Errorf("GetHeight, resp failed, status: %s", resp.Result.Status)
}
return resp.Result.LedgerIndex, nil
}
func (self *RestClient) SendRestRequest(addr string, data []byte) ([]byte, error) {
resp, err := self.restClient.Post(addr, "application/json", strings.NewReader(string(data)))
if err != nil {
return nil, fmt.Errorf("http post request:%s error:%s", data, err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, fmt.Errorf("read rest response body error:%s", err)
}
return body, nil
}
call getHeight method per second.
and all rpc request is sent by restClient, the code is generated rest client.
func NewRestClient() *RestClient {
return &RestClient{
restClient: &http.Client{
Transport: &http.Transport{
MaxIdleConnsPerHost: 5,
DisableKeepAlives: false,
IdleConnTimeout: time.Second * 300,
ResponseHeaderTimeout: time.Second * 300,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
Timeout: time.Second * 300,
},
}
}
why not use "subscribe" https://developers.ripple.com/subscribe.html
Because reconnection is a little troublesome.
and there are some new error info
Servers sometimes disconnect, does your script handle all the error cases? If there is an issue with the error messages returned by rippled, please kindly let us know.
I have deployed a ripple sync node, and monitor its' height and parse the latest closed ledger by rpc method
ledger_closed
andledger
. Usually I have lost my connection, because the rippled server return connection error, such asconnect reset by peer
,EOF
andconenct refuse
. And sometime rippled give the result while callledger_closed
rpc method, but the result cannot be parsed by json, the unmarshal error isinvalid character 'S' looking for beginning of value