thriftudp
1.0.0
中文说明
Thrift est l'un des meilleurs langages IDL pour le protocole UDP , pour son mot oneway clé de support de grammaire. Mais le package officiel ne prend en charge que TCP Transport & Server Framework.
L'objectif de ce package est d'étendre l' thrift avec le support UDP . Il fournit les fonctionnalités suivantes:
Pour le projet, github.com/jaegertracing/jaeger a une très belle implémentation dans une ancienne version d'épargne. Ce projet utilise simplement son implémentation transport avec une petite modification pour la nouvelle prise en charge de la version.
Veuillez vous assurer que Apache / Thrift a déjà été installé.
namespace go echo
struct Request {
1: string message ;
}
service Echo {
oneway void Ping( 1: Request request );
}
Utilisez thrift Générer le code Framework:
$: cd example
$: thrift -out thrift -r --gen go idl/echo.thrift package main
import (
"context"
"log"
"github.com/x-mod/routine"
"github.com/x-mod/thriftudp"
"github.com/x-mod/thriftudp/example/thrift/echo"
)
type echoImpl struct {}
func ( srv * echoImpl ) Ping ( ctx context. Context , request * echo. Request ) ( err error ) {
log . Println ( "echo Ping Request Message: " , request . Message )
return nil
}
func main () {
routine . Main ( context . TODO (), routine . ExecutorFunc ( func ( ctx context. Context ) error {
srv := thriftudp . NewServer (
thriftudp . ListenAddress ( "127.0.0.1:8888" ),
thriftudp . Processor (
echo . NewEchoProcessor ( & echoImpl {}),
2 ),
)
if err := srv . Open ( ctx ); err != nil {
return err
}
log . Println ( "serving at 127.0.0.1:8888 ..." )
return srv . Serv ( ctx )
}))
} package main
import (
"context"
"log"
"os"
"strings"
"github.com/apache/thrift/lib/go/thrift"
"github.com/x-mod/thriftudp/example/thrift/echo"
"github.com/x-mod/thriftudp/transport"
)
func main () {
tr , err := transport . NewTUDPClientTransport ( "127.0.0.1:8888" , "" )
if err != nil {
log . Println ( err )
return
}
client := echo . NewEchoClientFactory ( tr , thrift . NewTCompactProtocolFactory ())
req := echo . NewRequest ()
req . Message = strings . Join ( os . Args [ 1 :], " " )
if err := client . Ping ( context . TODO (), req ); err != nil {
log . Println ( err )
return
}
} Plus de détails, veuillez vérifier l' example .