thriftudp
1.0.0
中文说明
Thrift es uno de los mejores idiomas IDL para el protocolo UDP , para su palabra clave oneway de soporte gramatical. Pero el paquete oficial solo admite el marco de transporte y servidor TCP .
El propósito de este paquete es extender el thrift con soporte UDP . Proporciona las siguientes características:
Para el proyecto Github.com/jaegertracing/jaeger tiene una implementación muy hermosa en una vieja versión de segunda mano. Este proyecto solo usa su implementación transport con una pequeña modificación para el soporte de nueva versión.
Asegúrese de que ya se haya instalado Apache/Thrift.
namespace go echo
struct Request {
1: string message ;
}
service Echo {
oneway void Ping( 1: Request request );
}
Utilice thrift Genere el código de marco:
$: 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
}
} Más detalles, consulte el example .