• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang yarpc.Dispatcher类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang yarpc.ReqMeta类代码示例发布时间:2022-05-28
下一篇:
Golang yarpc.NewReqMeta函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap