Awesome
brokersrv: JSON-RPC 2.0 to NATS JetStream Gateway
brokersrv
is a transparent gateway on top of JSON-RPC 2.0 server that's passes RPC requests to NATS JetStream server.
It uses zenrpc package for processing RPC requests.
How to Use
- Configure brokersrv via TOML configuration and run it.
- Send RPC request to brokersrv.
- Use
github.com/vmkteam/brokersrv/pkg/rpcqueue
package in your RPC server for pulling RPC requests from NATS JetStream server.
Example
We have
testsrv
test rpc server with zenrpc package as RPC server listen onlocalhost:8080/rpc/
.NATS JetStream server
listen onlocalhost:4222
.brokersrv
with following configuration:
[Server]
Host = "localhost"
Port = 8071
[NATS]
URL = "nats://localhost:4222"
[Settings]
RpcServices = [ "testsrv" ]
Use brokersrv package in testrpc for processing RPC requests from NATS JetStream Server
...
import (
"github.com/vmkteam/brokersrv/pkg/rpcqueue"
)
...
nc, err := rpcqueue.NewClient("nats://localhost:4222", "testsrv")
...
rpcQueue := rpcqueue.New("testsrv", nc.JetStreamConn, zenrpcSrv, someLoggerPrintF)
go rpcQueue.Run()
Send test RPC request
Just send RPC request to localhost:8071/rpc/testsrv/
via Postman/curl. This request will pass into NATS JetStream server.
After that rpcQueue
in testsrv
will fetch this request from NATS JetStream server and pass it to own RPC server.