本文整理汇总了Golang中go/uber/org/yarpc.Dispatcher类的典型用法代码示例。如果您正苦于以下问题:Golang Dispatcher类的具体用法?Golang Dispatcher怎么用?Golang Dispatcher使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Dispatcher类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: JSON
// JSON starts an http run using JSON encoding
func JSON(t crossdock.T, dispatcher yarpc.Dispatcher) {
fatals := crossdock.Fatals(t)
client := json.New(dispatcher.Channel("oneway-test"))
token := getRandomID()
ack, err := client.CallOneway(
context.Background(),
yarpc.NewReqMeta().Procedure("echo/json"),
&jsonToken{Token: token},
)
// ensure channel hasn't been filled yet
select {
case <-serverCalledBack:
fatals.FailNow("oneway json test failed", "client waited for server to fill channel")
default:
}
fatals.NoError(err, "call to oneway/json failed: %v", err)
fatals.NotNil(ack, "ack is nil")
serverToken := <-serverCalledBack
fatals.Equal(token, string(serverToken), "Client/Server token mismatch")
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:26,代码来源:json.go
示例2: rawCall
func rawCall(dispatcher yarpc.Dispatcher, headers yarpc.Headers, procedure string,
token []byte) ([]byte, yarpc.CallResMeta, error) {
client := raw.New(dispatcher.Channel(serverName))
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
reqMeta := yarpc.NewReqMeta().Procedure(procedure).Headers(headers)
resBody, resMeta, err := client.Call(ctx, reqMeta, token)
return resBody, resMeta, err
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:12,代码来源:raw.go
示例3: jsonCall
func jsonCall(dispatcher yarpc.Dispatcher, headers yarpc.Headers, token string) (string, yarpc.CallResMeta, error) {
client := json.New(dispatcher.Channel(serverName))
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
reqMeta := yarpc.NewReqMeta().Procedure("echo").Headers(headers)
reqBody := &jsonEcho{Token: token}
var resBody jsonEcho
resMeta, err := client.Call(ctx, reqMeta, reqBody, &resBody)
return resBody.Token, resMeta, err
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:13,代码来源:json.go
示例4: thriftCall
func thriftCall(dispatcher yarpc.Dispatcher, headers yarpc.Headers, token string) (string, yarpc.CallResMeta, error) {
client := echoclient.New(dispatcher.Channel(serverName))
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
reqMeta := yarpc.NewReqMeta().Headers(headers)
ping := &echo.Ping{Beep: token}
resBody, resMeta, err := client.Echo(ctx, reqMeta, ping)
if err != nil {
return "", nil, err
}
return resBody.Boop, resMeta, err
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:15,代码来源:thrift.go
示例5: Thrift
// Thrift starts an http oneway run using Thrift encoding
func Thrift(t crossdock.T, dispatcher yarpc.Dispatcher) {
fatals := crossdock.Fatals(t)
client := onewayclient.New(dispatcher.Channel("oneway-test"))
ctx := context.Background()
token := getRandomID()
ack, err := client.Echo(ctx, nil, &token)
// ensure channel hasn't been filled yet
select {
case <-serverCalledBack:
fatals.FailNow("oneway thrift test failed", "client waited for server to fill channel")
default:
}
fatals.NoError(err, "call to Oneway::echo failed: %v", err)
fatals.NotNil(ack, "ack is nil")
serverToken := <-serverCalledBack
fatals.Equal(token, string(serverToken), "Client/Server token mismatch")
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:23,代码来源:thrift.go
示例6: runRaw
// runRaw tests if a yarpc client returns a remote timeout error behind the
// TimeoutError interface when a remote http handler returns a handler timeout.
func runRaw(t crossdock.T, disp yarpc.Dispatcher) {
assert := crossdock.Assert(t)
fatals := crossdock.Fatals(t)
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel()
ch := raw.New(disp.Channel("yarpc-test"))
_, _, err := ch.Call(ctx, yarpc.NewReqMeta().Procedure("handlertimeout/raw"), nil)
fatals.Error(err, "expected an error")
if transport.IsBadRequestError(err) {
t.Skipf("handlertimeout/raw method not implemented: %v", err)
return
}
assert.True(transport.IsTimeoutError(err), "returns a TimeoutError: %T", err)
form := strings.HasPrefix(err.Error(),
`Timeout: call to procedure "handlertimeout/raw" of service "service" from caller "caller" timed out after`)
assert.True(form, "must be a remote handler timeout: %q", err.Error())
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:24,代码来源:behavior.go
示例7: Raw
// Raw starts an http run using raw encoding
func Raw(t crossdock.T, dispatcher yarpc.Dispatcher) {
fatals := crossdock.Fatals(t)
client := raw.New(dispatcher.Channel("oneway-test"))
ctx := context.Background()
token := []byte(getRandomID())
ack, err := client.CallOneway(ctx, yarpc.NewReqMeta().Procedure("echo/raw"), token)
// ensure channel hasn't been filled yet
select {
case <-serverCalledBack:
fatals.FailNow("oneway raw test failed", "client waited for server to fill channel")
default:
}
fatals.NoError(err, "call to oneway/raw failed: %v", err)
fatals.NotNil(ack, "ack is nil")
serverToken := <-serverCalledBack
fatals.Equal(token, serverToken, "Client/Server token mismatch.")
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:23,代码来源:raw.go
示例8: register
func (h handler) register(dispatcher yarpc.Dispatcher) {
dispatcher.Register(json.Procedure("echo", h.handleEcho))
dispatcher.Register(json.Procedure("echoecho", h.handleEchoEcho))
}
开发者ID:yarpc,项目名称:yarpc-go,代码行数:4,代码来源:tracer_test.go
注:本文中的go/uber/org/yarpc.Dispatcher类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论