Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix custom filter samples #276

Merged
merged 9 commits into from
Oct 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .run/custom-client.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="custom-client" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="filter">
<module name="dubbo-go-samples" />
<working_directory value="$PROJECT_DIR$" />
<envs>
<env name="DUBBO_GO_CONFIG_PATH" value="$PROJECT_DIR$/filter/custom/go-client/conf/dubbogo.yml" />
</envs>
<kind value="PACKAGE" />
<package value="github.com/apache/dubbo-go-samples/filter/custom/go-client/cmd" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/rpc/dubbo/go-client/cmd/client.go" />
<method v="2" />
</configuration>
</component>
14 changes: 14 additions & 0 deletions .run/custom-server.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="custom-server" type="GoApplicationRunConfiguration" factoryName="Go Application" folderName="filter">
<module name="dubbo-go-samples" />
<working_directory value="$PROJECT_DIR$" />
<envs>
<env name="DUBBO_GO_CONFIG_PATH" value="$PROJECT_DIR$/filter/custom/go-server/conf/dubbogo.yml" />
</envs>
<kind value="PACKAGE" />
<package value="github.com/apache/dubbo-go-samples/filter/custom/go-server/cmd" />
<directory value="$PROJECT_DIR$" />
<filePath value="$PROJECT_DIR$/rpc/dubbo/go-client/cmd/client.go" />
<method v="2" />
</configuration>
</component>
3 changes: 0 additions & 3 deletions config-api/configcenter/nacos/go-client/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main

import (
"context"
"time"
)

import (
Expand Down Expand Up @@ -75,8 +74,6 @@ func main() {
panic(err)
}

time.Sleep(3 * time.Second)

logger.Info("start to test dubbo")
req := &api.HelloRequest{
Name: "laurence",
Expand Down
3 changes: 0 additions & 3 deletions config-api/configcenter/zookeeper/go-client/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main

import (
"context"
"time"
)

import (
Expand Down Expand Up @@ -73,8 +72,6 @@ func main() {
panic(err)
}

time.Sleep(3 * time.Second)

logger.Info("start to test dubbo")
req := &api.HelloRequest{
Name: "laurence",
Expand Down
3 changes: 0 additions & 3 deletions config-api/rpc/triple/go-client/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main

import (
"context"
"time"
)

import (
Expand Down Expand Up @@ -53,8 +52,6 @@ func main() {
panic(err)
}

time.Sleep(3 * time.Second)

logger.Info("start to test dubbo")
req := &api.HelloRequest{
Name: "laurence",
Expand Down
2 changes: 0 additions & 2 deletions configcenter/apollo/go-client/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main

import (
"context"
"time"
)

import (
Expand All @@ -41,7 +40,6 @@ func init() {
// export DUBBO_GO_CONFIG_PATH= PATH_TO_SAMPLES/helloworld/go-client/conf/dubbogo.yml
func main() {
config.Load()
time.Sleep(3 * time.Second)

logger.Info("start to test dubbo")
req := &api.HelloRequest{
Expand Down
2 changes: 0 additions & 2 deletions configcenter/nacos/go-client/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main

import (
"context"
"time"
)

import (
Expand All @@ -41,7 +40,6 @@ func init() {
// export DUBBO_GO_CONFIG_PATH= PATH_TO_SAMPLES/helloworld/go-client/conf/dubbogo.yml
func main() {
config.Load()
time.Sleep(3 * time.Second)

logger.Info("start to test dubbo")
req := &api.HelloRequest{
Expand Down
2 changes: 0 additions & 2 deletions configcenter/zookeeper/go-client/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main

import (
"context"
"time"
)

import (
Expand All @@ -41,7 +40,6 @@ func init() {
// export DUBBO_GO_CONFIG_PATH= PATH_TO_SAMPLES/helloworld/go-client/conf/dubbogo.yml
func main() {
config.Load()
time.Sleep(3 * time.Second)

logger.Info("start to test dubbo")
req := &api.HelloRequest{
Expand Down
2 changes: 0 additions & 2 deletions context/triple/go-client/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main

import (
"context"
"time"
)

import (
Expand All @@ -43,7 +42,6 @@ func init() {
// export DUBBO_GO_CONFIG_PATH= PATH_TO_SAMPLES/helloworld/go-client/conf/dubbogo.yml
func main() {
config.Load()
time.Sleep(3 * time.Second)

logger.Info("start to test dubbo")
req := &api.HelloRequest{
Expand Down
2 changes: 0 additions & 2 deletions direct/go-client/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package main

import (
"context"
"time"
)

import (
Expand All @@ -40,7 +39,6 @@ func main() {
if err := config.Load(); err != nil {
panic(err)
}
time.Sleep(3 * time.Second)

logger.Info("start to test dubbo")
req := &api.HelloRequest{
Expand Down
26 changes: 7 additions & 19 deletions filter/custom/go-client/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,22 @@ package main

import (
"context"
"time"
)

import (
"dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/config"
_ "dubbo.apache.org/dubbo-go/v3/imports"

hessian "github.com/apache/dubbo-go-hessian2"
)

import (
"github.com/apache/dubbo-go-samples/filter/custom/go-client/pkg"
"github.com/apache/dubbo-go-samples/api"
)

var userProvider = &pkg.UserProvider{}
var userProvider = &api.GreeterClientImpl{}

func init() {
config.SetConsumerService(userProvider)
hessian.RegisterPOJO(&pkg.User{})
}

func main() {
Expand All @@ -47,18 +43,10 @@ func main() {
panic(err)
}

var successCount, failCount int64
logger.Infof("\n\n\nstart to test dubbo")
for i := 0; i < 60; i++ {
time.Sleep(200 * time.Millisecond)
user, err := userProvider.GetUser(context.TODO(), "A001")
if err != nil {
failCount++
logger.Infof("error: %v\n", err)
} else {
successCount++
}
logger.Infof("response: %v\n", user)
logger.Infof("\n\n\nstart to test")
user, err := userProvider.SayHello(context.TODO(), &api.HelloRequest{Name: "laurence"})
if err != nil {
panic(err)
}
logger.Infof("failCount=%v, failCount=%v\n", successCount, failCount)
logger.Infof("get user = %+v", user)
}
49 changes: 49 additions & 0 deletions filter/custom/go-client/cmd/myfilter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 main

import (
"context"
"fmt"
)

import (
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/filter"
"dubbo.apache.org/dubbo-go/v3/protocol"
)

func init() {
extension.SetFilter("myClientFilter", NewMyClientFilter)
}

func NewMyClientFilter() filter.Filter {
return &MyClientFilter{}
}

type MyClientFilter struct {
}

func (f *MyClientFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
fmt.Println("MyClientFilter Invoke is called, method Name = ", invocation.MethodName())
return invoker.Invoke(ctx, invocation)
}
func (f *MyClientFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, protocol protocol.Invocation) protocol.Result {
fmt.Println("MyClientFilter OnResponse is called")
return result
}
7 changes: 4 additions & 3 deletions filter/custom/go-client/conf/dubbogo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,17 @@
dubbo:
registries:
demoZK:
protocolIDs: zookeeper
protocol: zookeeper
timeout: 3s
address: 127.0.0.1:2181
consumer:
filter: myClientFilter
check: true
request_timeout: 3s
connect_timeout: 3s
registryIDs:
- demoZK
references:
UserProvider:
protocolIDs: dubbo
GreeterClientImpl:
protocol: tri
interface: org.apache.dubbo.UserProvider
49 changes: 49 additions & 0 deletions filter/custom/go-server/cmd/myfilter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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 main

import (
"context"
"fmt"
)

import (
"dubbo.apache.org/dubbo-go/v3/common/extension"
"dubbo.apache.org/dubbo-go/v3/filter"
"dubbo.apache.org/dubbo-go/v3/protocol"
)

func init() {
extension.SetFilter("myServerFilter", NewMyServerFilter)
}

func NewMyServerFilter() filter.Filter {
return &MyServerFilter{}
}

type MyServerFilter struct {
}

func (f *MyServerFilter) Invoke(ctx context.Context, invoker protocol.Invoker, invocation protocol.Invocation) protocol.Result {
fmt.Println("MyServerFilter Invoke is called, method Name = ", invocation.MethodName())
return invoker.Invoke(ctx, invocation)
}
func (f *MyServerFilter) OnResponse(ctx context.Context, result protocol.Result, invoker protocol.Invoker, protocol protocol.Invocation) protocol.Result {
fmt.Println("MyServerFilter OnResponse is called")
return result
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,36 @@
* limitations under the License.
*/

package pkg
package main

import (
"context"
"time"
)

type User struct {
ID string
Name string
Age int32
Time time.Time
import (
"dubbo.apache.org/dubbo-go/v3/common/logger"
"dubbo.apache.org/dubbo-go/v3/config"
_ "dubbo.apache.org/dubbo-go/v3/imports"
)

import (
"github.com/apache/dubbo-go-samples/api"
)

type GreeterProvider struct {
api.GreeterProviderBase
}

type UserProvider struct {
GetUser func(ctx context.Context, req string) (*User, error)
func (s *GreeterProvider) SayHello(ctx context.Context, in *api.HelloRequest) (*api.User, error) {
logger.Infof("Dubbo3 GreeterProvider get user name = %s\n", in.Name)
return &api.User{Name: "Hello " + in.Name, Id: "12345", Age: 21}, nil
}

func (u *User) JavaClassName() string {
return "org.apache.dubbo.User"
// export DUBBO_GO_CONFIG_PATH= PATH_TO_SAMPLES/helloworld/go-server/conf/dubbogo.yml
func main() {
config.SetProviderService(&GreeterProvider{})
if err := config.Load(); err != nil {
panic(err)
}
select {}
}
Loading