version: "2.7"
server:
command: "php bin/road-runner-console baldinof:roadrunner:worker"
env:
- APP_RUNTIME: Baldinof\RoadRunnerBundle\Runtime\Runtime
## Go воркер
go_worker:
command: "go run main.go"
env:
- GOOS: linux
- GOARCH: amd64
package main
import (
"fmt"
"net"
"net/rpc"
goridgeRpc "github.com/roadrunner-server/goridge/v3/pkg/rpc"
)
type App struct{}
func (s *App) Hi(name string, r *string) error {
*r = fmt.Sprintf("Hello, %s!", name)
return nil
}
func main() {
fmt.Println("Привет, мир!")
ln, err := net.Listen("tcp", ":6001")
if err != nil {
panic(err)
}
_ = rpc.Register(new(App))
for {
conn, err := ln.Accept()
if err != nil {
continue
}
_ = conn
go rpc.ServeCodec(goridgeRpc.NewCodec(conn))
}
}
$tcpRPC = new Goridge\RPC\RPC(Goridge\Relay::create('tcp://127.0.0.1:6001'));
$r = $tcpRPC->call("App.Hi", "Antony");
var_dump(
$r
); echo __METHOD__.':'.__LINE__;die();
bin/rr-server serve .rr.dev.yaml -d
{"level":"debug","ts":1729072653.5290942,"logger":"rpc","msg":"plugin was started","address":"tcp://127.0.0.1:6001","list of the plugins with RPC methods:":["informer","resetter","app"]}
[INFO] RoadRunner server started; version: 2.12.3, buildtime: 2023-02-16T13:08:41+0000
"exception" => Spiral\Goridge\RPC\Exception\ServiceException^ {
#message: "Error 'rpc: can't find service App.Hi' on tcp://127.0.0.1:6001"
$tcpRPC = new Goridge\RPC\RPC(Goridge\Relay::create('tcp://go_worker:6001'));