LaurenceLiZhixin commented on a change in pull request #258: URL: https://github.com/apache/dubbo-go-samples/pull/258#discussion_r719282648
########## File path: filter/tpslimit/go-server/pkg/limit_strategy.go ########## @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package pkg + +import ( + "math/rand" +) + +import ( + "dubbo.apache.org/dubbo-go/v3/common/extension" + "dubbo.apache.org/dubbo-go/v3/filter" + + "github.com/dubbogo/gost/log" +) + +func init() { + /* + * register your implementation and them using it like: + * + * "UserProvider": Review comment: 最好吧引号去掉 ########## File path: filter/tpslimit/go-server/tests/integration/userprovider_test.go ########## @@ -0,0 +1,50 @@ +// +build integration + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package integration + +import ( + "context" + "strings" + "testing" +) + +import ( + "github.com/stretchr/testify/assert" +) + +func TestGetUser(t *testing.T) { + user := &User{} + var err error + + // loop 50 times to make sure rejection happens + for i := 0; i < 50; i++ { + if user, err = userProvider.GetUser(context.TODO(), []interface{}{"A001"}); err != nil { Review comment: 同上,我认为这次改完就可以合并了 ########## File path: filter/tpslimit/go-server/pkg/limit_strategy.go ########## @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package pkg + +import ( + "math/rand" +) + +import ( + "dubbo.apache.org/dubbo-go/v3/common/extension" + "dubbo.apache.org/dubbo-go/v3/filter" + + "github.com/dubbogo/gost/log" +) + +func init() { + /* + * register your implementation and them using it like: + * + * "UserProvider": + * registry: "hangzhouzk" + * protocol : "dubbo" + * interface : "com.ikurento.user.UserProvider" + * ... # other configuration + * tps.limiter: "method-service" # the name of limiter + * tps.limit.strategy: "RandomLimitStrategy" + */ + extension.SetTpsLimitStrategy("RandomLimitStrategy", &RandomTpsLimitStrategyCreator{}) +} + +/** + * The RandomTpsLimitStrategy should not be singleton because different TpsLimiter will create many instances. + * we won't want them affect each other. + */ +type RandomTpsLimitStrategy struct { Review comment: 这个结构继承了哪个接口,需要实现的函数IsAllowable 的意义是什么。需要给出注释说明。 以及下面的RandomTpsLimitStrategyCreator 也是。 ########## File path: filter/tpslimit/go-server/pkg/reject_handler.go ########## @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package pkg + +import ( + "errors" + "sync" +) + +import ( + "dubbo.apache.org/dubbo-go/v3/common" + "dubbo.apache.org/dubbo-go/v3/common/extension" + "dubbo.apache.org/dubbo-go/v3/common/logger" + "dubbo.apache.org/dubbo-go/v3/filter" + "dubbo.apache.org/dubbo-go/v3/protocol" +) + +func init() { + /* + * register your custom implementation into filter. + * "DefaultValueHandler" is the name used in configure file, like server.yml: + * "UserProvider": + * registry: "hangzhouzk" Review comment: 同,引号需要去掉 ########## File path: filter/tpslimit/go-server/docker/docker-compose.yml ########## @@ -0,0 +1,9 @@ +version: '3' Review comment: docker文件夹可以去掉了,目前集成测试不依赖这个了 ########## File path: filter/tpslimit/go-server/conf/dubbogo.yml ########## @@ -0,0 +1,29 @@ +# dubbo server yaml configure file + + +dubbo: + registries: + demoZK: + protocol: zookeeper + timeout: 3s + address: 127.0.0.1:2181 + protocols: + dubbo: + name: dubbo + port: 20000 + provider: + registry: + - demoZK + services: + UserProvider: + protocol: dubbo + interface: org.apache.dubbo.UserProvider + loadbalance: random + warmup: 100 + cluster: failover + tps.limiter: method-service Review comment: 这些字段的含义是什么,有哪些可选项,需要注释出来,给用户说明。 ########## File path: filter/tpslimit/go-server/pkg/user.go ########## @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package pkg + +import ( + "context" + "time" +) + +import ( + "github.com/dubbogo/gost/log" +) + +type User struct { + ID string + Name string + Age int32 + Time time.Time +} Review comment: 是这样的,api目录下的User是pb序列化定义的。在你的例子中使用hessian序列化,需要自己定义User结构。 ########## File path: filter/tpslimit/go-server/tests/integration/main_test.go ########## @@ -0,0 +1,61 @@ +// +build integration + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package integration + +import ( + "context" + "os" + "testing" + "time" +) + +import ( + "dubbo.apache.org/dubbo-go/v3/config" + _ "dubbo.apache.org/dubbo-go/v3/imports" + + hessian "github.com/apache/dubbo-go-hessian2" +) + +var userProvider = new(UserProvider) + +func TestMain(m *testing.M) { + config.SetConsumerService(userProvider) + hessian.RegisterPOJO(&User{}) + config.Load() + + time.Sleep(3 * time.Second) + + os.Exit(m.Run()) +} + +type User struct { + ID string + Name string + Age int32 + Time time.Time +} + +type UserProvider struct { + GetUser func(ctx context.Context, req []interface{}) (*User, error) +} + +func (User) JavaClassName() string { Review comment: func (u *User) ########## File path: filter/tpslimit/go-client/pkg/user.go ########## @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package pkg + +import ( + "context" + "time" +) + +type User struct { + ID string + Name string + Age int32 + Time time.Time +} + +type UserProvider struct { + GetUser func(ctx context.Context, req []string) (*User, error) + Ch chan *User +} + +func (User) JavaClassName() string { Review comment: func (u *User) JavaClassName() string{ ########## File path: filter/tpslimit/go-server/tests/integration/main_test.go ########## @@ -0,0 +1,61 @@ +// +build integration + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package integration + +import ( + "context" + "os" + "testing" + "time" +) + +import ( + "dubbo.apache.org/dubbo-go/v3/config" + _ "dubbo.apache.org/dubbo-go/v3/imports" + + hessian "github.com/apache/dubbo-go-hessian2" +) + +var userProvider = new(UserProvider) + +func TestMain(m *testing.M) { + config.SetConsumerService(userProvider) + hessian.RegisterPOJO(&User{}) + config.Load() + + time.Sleep(3 * time.Second) + + os.Exit(m.Run()) +} + +type User struct { + ID string + Name string + Age int32 + Time time.Time +} + +type UserProvider struct { + GetUser func(ctx context.Context, req []interface{}) (*User, error) Review comment: 这个老接口,需要改成具体类型 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
