Skip to content

Commit

Permalink
Support websocket to register nacos (#33)
Browse files Browse the repository at this point in the history
* add nacos support for websocket

* lint code
  • Loading branch information
giskook authored Nov 6, 2023
1 parent c05ac23 commit 6de0441
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 5 deletions.
7 changes: 6 additions & 1 deletion config/environments/local/local.node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@ EnableL2SuggestedGasPricePolling = true
[RPC.WebSockets]
Enabled = true
Port = 8546
[RCP.Nacos]
[RPC.Nacos]
URLs = ""
NamespaceId = "public"
ApplicationName = ""
ExternalListenAddr = "127.0.0.1:8123"
[RPC.NacosWs]
URLs = ""
NamespaceId = "public"
ApplicationName = ""
Expand Down
7 changes: 6 additions & 1 deletion config/environments/mainnet/node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ EnableL2SuggestedGasPricePolling = false
[RPC.WebSockets]
Enabled = true
Port = 8546
[RCP.Nacos]
[RPC.Nacos]
URLs = ""
NamespaceId = "public"
ApplicationName = ""
ExternalListenAddr = "127.0.0.1:8123"
[RPC.NacosWs]
URLs = ""
NamespaceId = "public"
ApplicationName = ""
Expand Down
7 changes: 6 additions & 1 deletion config/environments/testnet/node.config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,12 @@ EnableL2SuggestedGasPricePolling = false
[RPC.WebSockets]
Enabled = true
Port = 8546
[RCP.Nacos]
[RPC.Nacos]
URLs = ""
NamespaceId = "public"
ApplicationName = ""
ExternalListenAddr = "127.0.0.1:8123"
[RPC.NacosWs]
URLs = ""
NamespaceId = "public"
ApplicationName = ""
Expand Down
2 changes: 1 addition & 1 deletion docs/config-file/node-config-doc.html

Large diffs are not rendered by default.

69 changes: 69 additions & 0 deletions docs/config-file/node-config-doc.md
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,7 @@ FreeGasAddress="0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
| - [TraceBatchUseHTTPS](#RPC_TraceBatchUseHTTPS ) | No | boolean | No | - | TraceBatchUseHTTPS enables, in the debug_traceBatchByNum endpoint, the use of the HTTPS protocol (instead of HTTP)<br />to do the parallel requests to RPC.debug_traceTransaction endpoint |
| - [EnablePendingTransactionFilter](#RPC_EnablePendingTransactionFilter ) | No | boolean | No | - | EnablePendingTransactionFilter enables pending transaction filter that can support query L2 pending transaction |
| - [Nacos](#RPC_Nacos ) | No | object | No | - | Nacos configuration |
| - [NacosWs](#RPC_NacosWs ) | No | object | No | - | NacosWs configuration |

### <a name="RPC_Host"></a>8.1. `RPC.Host`

Expand Down Expand Up @@ -1053,6 +1054,74 @@ ApplicationName=""
ExternalListenAddr=""
```

### <a name="RPC_NacosWs"></a>8.13. `[RPC.NacosWs]`

**Type:** : `object`
**Description:** NacosWs configuration

| Property | Pattern | Type | Deprecated | Definition | Title/Description |
| -------------------------------------------------------- | ------- | ------ | ---------- | ---------- | ------------------------------------------------------------------------------------------ |
| - [URLs](#RPC_NacosWs_URLs ) | No | string | No | - | URLs nacos server urls for discovery service of rest api, url is separated by "," |
| - [NamespaceId](#RPC_NacosWs_NamespaceId ) | No | string | No | - | NamespaceId nacos namepace id for discovery service of rest api |
| - [ApplicationName](#RPC_NacosWs_ApplicationName ) | No | string | No | - | ApplicationName rest application name in nacos |
| - [ExternalListenAddr](#RPC_NacosWs_ExternalListenAddr ) | No | string | No | - | ExternalListenAddr Set the rest-server external ip and port, when it is launched by Docker |

#### <a name="RPC_NacosWs_URLs"></a>8.13.1. `RPC.NacosWs.URLs`

**Type:** : `string`

**Default:** `""`

**Description:** URLs nacos server urls for discovery service of rest api, url is separated by ","

**Example setting the default value** (""):
```
[RPC.NacosWs]
URLs=""
```

#### <a name="RPC_NacosWs_NamespaceId"></a>8.13.2. `RPC.NacosWs.NamespaceId`

**Type:** : `string`

**Default:** `""`

**Description:** NamespaceId nacos namepace id for discovery service of rest api

**Example setting the default value** (""):
```
[RPC.NacosWs]
NamespaceId=""
```

#### <a name="RPC_NacosWs_ApplicationName"></a>8.13.3. `RPC.NacosWs.ApplicationName`

**Type:** : `string`

**Default:** `""`

**Description:** ApplicationName rest application name in nacos

**Example setting the default value** (""):
```
[RPC.NacosWs]
ApplicationName=""
```

#### <a name="RPC_NacosWs_ExternalListenAddr"></a>8.13.4. `RPC.NacosWs.ExternalListenAddr`

**Type:** : `string`

**Default:** `""`

**Description:** ExternalListenAddr Set the rest-server external ip and port, when it is launched by Docker

**Example setting the default value** (""):
```
[RPC.NacosWs]
ExternalListenAddr=""
```

## <a name="Synchronizer"></a>9. `[Synchronizer]`

**Type:** : `object`
Expand Down
27 changes: 27 additions & 0 deletions docs/config-file/node-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,33 @@
"additionalProperties": false,
"type": "object",
"description": "Nacos configuration"
},
"NacosWs": {
"properties": {
"URLs": {
"type": "string",
"description": "URLs nacos server urls for discovery service of rest api, url is separated by \",\"",
"default": ""
},
"NamespaceId": {
"type": "string",
"description": "NamespaceId nacos namepace id for discovery service of rest api",
"default": ""
},
"ApplicationName": {
"type": "string",
"description": "ApplicationName rest application name in nacos",
"default": ""
},
"ExternalListenAddr": {
"type": "string",
"description": "ExternalListenAddr Set the rest-server external ip and port, when it is launched by Docker",
"default": ""
}
},
"additionalProperties": false,
"type": "object",
"description": "NacosWs configuration"
}
},
"additionalProperties": false,
Expand Down
5 changes: 4 additions & 1 deletion jsonrpc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ type Config struct {
EnablePendingTransactionFilter bool `mapstructure:"EnablePendingTransactionFilter"`

// Nacos configuration
Nacos NacosConfig `mspstructure:"Nacos"`
Nacos NacosConfig `mapstructure:"Nacos"`

// NacosWs configuration
NacosWs NacosConfig `mapstructure:"NacosWs"`
}

// WebSocketsConfig has parameters to config the rpc websocket support
Expand Down
5 changes: 5 additions & 0 deletions jsonrpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,4 +422,9 @@ func (s *Server) registerNacos() {
if s.config.Nacos.URLs != "" {
nacos.StartNacosClient(s.config.Nacos.URLs, s.config.Nacos.NamespaceId, s.config.Nacos.ApplicationName, s.config.Nacos.ExternalListenAddr)
}

// start nacos client for registering restful service
if s.config.NacosWs.URLs != "" {
nacos.StartNacosClient(s.config.NacosWs.URLs, s.config.NacosWs.NamespaceId, s.config.NacosWs.ApplicationName, s.config.NacosWs.ExternalListenAddr)
}
}

0 comments on commit 6de0441

Please sign in to comment.