mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-25 00:58:45 +05:00
json made optional for all rpc encodings
This commit is contained in:
@@ -36,6 +36,7 @@ var (
|
||||
httpApiAddress = flag.String("httpapiaddr", "127.0.0.1:8000", "Http API server address (localhost:2002)")
|
||||
freeswitchsrv = flag.String("freeswitchsrv", "localhost:8021", "freeswitch address host:port")
|
||||
freeswitchpass = flag.String("freeswitchpass", "ClueCon", "freeswitch address host:port")
|
||||
js = flag.Bool("json", false, "use JSON for RPC encoding")
|
||||
bal *balancer.Balancer
|
||||
balancerRWMutex sync.RWMutex
|
||||
)
|
||||
@@ -92,7 +93,7 @@ func main() {
|
||||
|
||||
go StopSingnalHandler()
|
||||
go listenToRPCRaterRequests()
|
||||
go listenToJsonRPCRequests()
|
||||
go listenToRPCRequests()
|
||||
|
||||
sm := &sessionmanager.FSSessionManager{}
|
||||
sm.Connect(sessionmanager.NewRPCBalancerSessionDelegate(bal), *freeswitchsrv, *freeswitchpass)
|
||||
|
||||
@@ -97,7 +97,7 @@ func (r *Responder) Status(arg timespans.CallDescriptor, replay *string) (err er
|
||||
/*
|
||||
Creates the json rpc server.
|
||||
*/
|
||||
func listenToJsonRPCRequests() {
|
||||
func listenToRPCRequests() {
|
||||
l, err := net.Listen("tcp", *jsonRpcAddress)
|
||||
defer l.Close()
|
||||
|
||||
@@ -111,13 +111,19 @@ func listenToJsonRPCRequests() {
|
||||
rpc.Register(responder)
|
||||
|
||||
for {
|
||||
c, err := l.Accept()
|
||||
conn, err := l.Accept()
|
||||
if err != nil {
|
||||
log.Printf("accept error: %s", c)
|
||||
log.Printf("accept error: %s", conn)
|
||||
continue
|
||||
}
|
||||
|
||||
log.Printf("connection started: %v", c.RemoteAddr())
|
||||
go jsonrpc.ServeConn(c)
|
||||
log.Printf("connection started: %v", conn.RemoteAddr())
|
||||
if *js {
|
||||
// log.Print("json encoding")
|
||||
go jsonrpc.ServeConn(conn)
|
||||
} else {
|
||||
// log.Print("gob encoding")
|
||||
go rpc.ServeConn(conn)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,9 @@ var (
|
||||
redissrv = flag.String("redissrv", "127.0.0.1:6379", "redis address host:port")
|
||||
redisdb = flag.Int("redisdb", 10, "redis database number")
|
||||
listen = flag.String("listen", "127.0.0.1:1234", "listening address host:port")
|
||||
standalone = flag.Bool("standalone", false, "start standalone server (no balancer), and use JSON for RPC encoding")
|
||||
standalone = flag.Bool("standalone", false, "start standalone server (no balancer)")
|
||||
freeswitch = flag.Bool("freeswitch", false, "connect to freeswitch server")
|
||||
json = flag.Bool("json", false, "use JSON for RPC encoding")
|
||||
storage Responder
|
||||
)
|
||||
|
||||
@@ -122,10 +124,11 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatalf("Cannot open storage: %v", err)
|
||||
}
|
||||
if *standalone {
|
||||
if *freeswitch {
|
||||
sm := &sessionmanager.FSSessionManager{}
|
||||
sm.Connect(sessionmanager.NewDirectSessionDelegate(getter), *freeswitchsrv, *freeswitchpass)
|
||||
} else {
|
||||
}
|
||||
if !*standalone {
|
||||
go RegisterToServer(balancer, listen)
|
||||
go StopSingnalHandler(balancer, listen, getter)
|
||||
}
|
||||
@@ -155,7 +158,7 @@ func main() {
|
||||
continue
|
||||
}
|
||||
log.Printf("connection started: %v", conn.RemoteAddr())
|
||||
if *standalone {
|
||||
if *json {
|
||||
// log.Print("json encoding")
|
||||
go jsonrpc.ServeConn(conn)
|
||||
} else {
|
||||
|
||||
@@ -23,11 +23,13 @@ import (
|
||||
"github.com/cgrates/cgrates/sessionmanager"
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
)
|
||||
|
||||
var (
|
||||
standalone = flag.Bool("standalone", false, "run standalone (run as a rater)")
|
||||
json = flag.Bool("json", false, "use JSON for RPC encoding")
|
||||
balancer = flag.String("balancer", "127.0.0.1:2000", "balancer address host:port")
|
||||
freeswitchsrv = flag.String("freeswitchsrv", "localhost:8021", "freeswitch address host:port")
|
||||
freeswitchpass = flag.String("freeswitchpass", "ClueCon", "freeswitch address host:port")
|
||||
@@ -46,7 +48,12 @@ func main() {
|
||||
if *standalone {
|
||||
sm.Connect(sessionmanager.NewDirectSessionDelegate(getter), *freeswitchsrv, *freeswitchpass)
|
||||
} else {
|
||||
client, err := jsonrpc.Dial("tcp", *balancer)
|
||||
var client *rpc.Client
|
||||
if *json {
|
||||
client, err = jsonrpc.Dial("tcp", *balancer)
|
||||
} else {
|
||||
client, err = rpc.Dial("tcp", *balancer)
|
||||
}
|
||||
if err != nil {
|
||||
log.Fatalf("could not connect to balancer: %v", err)
|
||||
}
|
||||
|
||||
@@ -21,6 +21,7 @@ package main
|
||||
import (
|
||||
"github.com/cgrates/cgrates/timespans"
|
||||
"log"
|
||||
"net/rpc"
|
||||
"net/rpc/jsonrpc"
|
||||
"time"
|
||||
"flag"
|
||||
@@ -28,6 +29,7 @@ import (
|
||||
|
||||
var (
|
||||
runs = flag.Int("runs", 10000, "stress cycle number")
|
||||
json = flag.Bool("json", false, "use JSON for RPC encoding")
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -36,7 +38,16 @@ func main() {
|
||||
t2 := time.Date(2012, time.February, 02, 18, 30, 0, 0, time.UTC)
|
||||
cd := timespans.CallDescriptor{Direction: "OUT", TOR: "0", Tenant: "vdf", Subject: "rif", Destination: "0256", TimeStart: t1, TimeEnd: t2}
|
||||
result := timespans.CallCost{}
|
||||
client, _ := jsonrpc.Dial("tcp", "localhost:1234")
|
||||
var client *rpc.Client
|
||||
var err error
|
||||
if *json {
|
||||
client, err = jsonrpc.Dial("tcp", "localhost:1234")
|
||||
} else {
|
||||
client, err = rpc.Dial("tcp", "localhost:1234")
|
||||
}
|
||||
if err != nil {
|
||||
log.Panic("Could not connect to rater: ", err)
|
||||
}
|
||||
i := 0
|
||||
start := time.Now()
|
||||
for j := 0; j < *runs; j++ {
|
||||
|
||||
Reference in New Issue
Block a user