Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xizhibei/go-reverse-rpc
A remote procedure call (RPC) framework designed for connecting to devices remotely.
https://github.com/xizhibei/go-reverse-rpc
json mqtt protobuf reverse-rpc rpc rpc-framework
Last synced: 4 days ago
JSON representation
A remote procedure call (RPC) framework designed for connecting to devices remotely.
- Host: GitHub
- URL: https://github.com/xizhibei/go-reverse-rpc
- Owner: xizhibei
- License: mit
- Created: 2023-11-20T08:08:01.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2025-01-22T13:35:28.000Z (29 days ago)
- Last Synced: 2025-01-22T14:29:45.612Z (29 days ago)
- Topics: json, mqtt, protobuf, reverse-rpc, rpc, rpc-framework
- Language: Go
- Homepage:
- Size: 280 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# Go reverse RPC
A remote procedure call (RPC) framework designed for connecting to devices remotely. It enables the "server" to call functions provided by the "client".
[](https://github.com/xizhibei/go-reverse-rpc/actions/workflows/go.yml)
[](https://goreportcard.com/report/github.com/xizhibei/go-reverse-rpc)
[](https://pkg.go.dev/github.com/xizhibei/go-reverse-rpc?tab=doc)## Features
- Supports multiple communication protocols - currently implemented MQTT 3.1/3.11
- Allows encoding data in different formats - currently supports JSON and Protobuf
- Provides monitoring metrics for system insights
- Implements error handling mechanisms for reliability#### TODO
- Open telemetry support
- MQTT v5 protocol support
- WebSocket protocol support
- AMQP protocol support## Installation
```bash
go get github.com/xizhibei/go-reverse-rpc@latest
```## Usage
#### Server create
```go
import (
"github.com/xizhibei/go-reverse-rpc/mqttpb"
"github.com/xizhibei/go-reverse-rpc/mqttadapter"
)mqttClient, err := mqttadapter.New("tcp://localhost", "client-id-123456-server")
if err != nil {
panic(err)
}server := mqttpb.NewServer(
mqttClient,
"example-prefix",
"device-123456",
)
```#### Client create
```go
import (
"github.com/xizhibei/go-reverse-rpc/mqttpb"
"github.com/xizhibei/go-reverse-rpc/mqttadapter"
)mqttClient, err := mqttadapter.New("tcp://localhost", "client-id-123456-client")
if err != nil {
panic(err)
}client := mqttpb.New(
mqttClient,
"example-prefix",
mqttpb.ContentEncoding_GZIP,
)
```#### Register handler on server side
```go
import (
rrpc "github.com/xizhibei/go-reverse-rpc"
)server.Register("example-method", &rrpc.Handler{
Method: func(c rrpc.Context) {
var req Req
err := c.Bind(&req)
if err != nil {
c.ReplyError(rrpc.RPCStatusClientError, err)
return
}// your business logic ...
c.ReplyOK(req)
},
Timeout: 5 * time.Second,
})
```#### Call on client side
```go
var res Req
err := client.Call(context.Background(), "device-123456", "example-method", &reqParams, &res)
```#### Server create options
```go
rrpc.WithServerName(name string) // Used to set the name of the server. For monitoring purposes, metrics labels will use this name.
rrpc.WithLogResponse(logResponse bool) // Used to enable or disable logging of response.
rrpc.WithLimiter(d time.Duration, count int) // Used to set the limiter duration and count for the server.
rrpc.WithLimiterReject() // Used to allow the server to reject requests when the limiter is full. This is default behavior.
rrpc.WithLimiterWait() // Used to allow the server to wait for available resources instead of rejecting requests when the limiter is full.
rrpc.WithWorkerNum(count int) // Used to set the number of workers for the server.
```## License
Go reverse RPC released under MIT license, refer [LICENSE](LICENSE) file.