thriftudp
1.0.0
中文說明
Thrift是UDP協議的最佳IDL語言之一,因為它的語法支持oneway關鍵字。但是官方軟件包僅支持TCP運輸和服務器框架。
該軟件包的目的是通過UDP支持擴展thrift 。它提供以下功能:
對於項目,github.com/jaegertracing/jaeger在舊的舊貨版中具有非常漂亮的實現。該項目只需使用其transport實施,並進行了微小的修改以進行新版本支持。
請確保已經安裝了Apache/Thrift。
namespace go echo
struct Request {
1: string message ;
}
service Echo {
oneway void Ping( 1: Request request );
}
使用thrift生成框架代碼:
$: 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
}
}更多詳細信息,請檢查example 。