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.
- 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.
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" ]
...
import (
"github.com/nats-io/nats.go"
"github.com/vmkteam/brokersrv/pkg/rpcqueue"
)
...
nc, err := nats.Connect("nats://localhost:4222", nats.Name("testsrv"), nats.MaxReconnects(100), nats.ReconnectWait(3*time.Second))
...
js, err := nc.JetStream()
...
rpcQueue := rpcqueue.New("testsrv", js, zenrpcSrv, someLoggerPrintF)
go rpcQueue.Run()
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.