apache / dubbo-go

Go Implementation For Apache Dubbo .
https://dubbo.apache.org/
Apache License 2.0
4.71k stars 925 forks source link

[QUESTION]如何正确启动 dubbo-go + nacos 泛化client? #1375

Closed xmsz closed 2 years ago

xmsz commented 3 years ago
package main

import (
    "context"
    "time"

    "dubbo.apache.org/dubbo-go/v3/config"
    gxlog "github.com/dubbogo/gost/log"

    _ "github.com/apache/dubbo-go/cluster/cluster_impl"

    _ "github.com/apache/dubbo-go/cluster/loadbalance"

    _ "github.com/apache/dubbo-go/common/proxy/proxy_factory"

    _ "github.com/apache/dubbo-go/filter/filter_impl"

    _ "github.com/apache/dubbo-go/registry/protocol"

    _ "github.com/apache/dubbo-go/registry/nacos"
)

var (
    appName        = "RankConsumer"
    referenceConig = config.ReferenceConfig{
        InterfaceName: "org.apache.dubbo.RankProvider",
        Cluster:       "failover",
        Registry:      "nacos",
        Protocol:      "tri",
        Generic:       true,
    }
)

func init() {
    referenceConig.GenericLoad(appName)

    time.Sleep(time.Second * 3)

    select {}
}

func main() {

    resp, err := referenceConig.GetRPCService().(*config.GenericService).Invoke(
        context.TODO(),
        []interface{}{
            "GetOfficialNumRank",
            // []string{"java.lang.String"},
            // []interface{}{"A003"},
        },
    )

    if err != nil {
        panic((err))
    }
    gxlog.CInfo("res: %+v\n", resp)
}

出现错误

2021-08-10T18:06:50.528+0800    WARN    runtime/proc.go:6308    InitLog with error ioutil.ReadFile(file:../profiles/dev/log.yml) = error:open ../profiles/dev/log.yml: no such file or directory
2021/08/10 18:06:50 [InitLog] warn: log configure file name is nil
2021/08/10 18:06:50 [consumerInit] application configure(consumer) file name is nil
2021/08/10 18:06:50 [providerInit] application configure(provider) file name is nil
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x44f0dfc]

goroutine 1 [running]:
dubbo.apache.org/dubbo-go/v3/config.(*ReferenceConfig).getURLMap(0x4c4c7c0, 0x3)
    /go/pkg/mod/dubbo.apache.org/dubbo-go/v3@v3.0.0-rc2/config/reference_config.go:255 +0xd9c
dubbo.apache.org/dubbo-go/v3/config.(*ReferenceConfig).Refer(0x4c4c7c0, 0x46bd880, 0xc000304e28)
    /go/pkg/mod/dubbo.apache.org/dubbo-go/v3@v3.0.0-rc2/config/reference_config.go:97 +0x99
dubbo.apache.org/dubbo-go/v3/config.(*ReferenceConfig).GenericLoad(0x4c4c7c0, 0x47962b1, 0xc)
    /go/pkg/mod/dubbo.apache.org/dubbo-go/v3@v3.0.0-rc2/config/reference_config.go:287 +0x10d
main.init.0()
exit status 2
xmsz commented 3 years ago

如果通过RPCService调用

resp, err := config.GetRPCService(ProviderImplName).(*config.GenericService).Invoke(
        context.TODO(),
        []interface{}{
            "GetOfficialNumRank",
            []string{ProviderImplName},
            []interface{}{accountId},
        },
    )

则出现

panic: reflect: call of reflect.Value.Call on zero Value

goroutine 20 [running]:
reflect.flag.mustBe(...)
    /usr/local/go/src/reflect/value.go:221
reflect.Value.Call(0x0, 0x0, 0x0, 0xc0000bd6f8, 0x1, 0x10, 0x0, 0x0, 0xc000340be8)
    /usr/local/go/src/reflect/value.go:335 +0x174
github.com/dubbogo/triple/pkg/triple.getInvoker(0x49bf980, 0xc0001a88e8, 0xc000144050, 0x0, 0x4a05e00)
    /go/pkg/mod/github.com/dubbogo/triple@v1.0.2/pkg/triple/dubbo3_conn.go:61 +0x1ba
github.com/dubbogo/triple/pkg/triple.NewTripleClient(0x49bf980, 0xc0001a88e8, 0xc000164180, 0xc000164180, 0xc00000e438, 0x0)
    /go/pkg/mod/github.com/dubbogo/triple@v1.0.2/pkg/triple/dubbo3_client.go:72 +0x211
dubbo.apache.org/dubbo-go/v3/protocol/dubbo3.NewDubboInvoker(0xc000160180, 0x4a04401, 0x4b59290, 0x5226cf0)
    ...
ChangedenCZD commented 3 years ago

你可以参照这个测试用例试试https://github.com/apache/dubbo-go/blob/3.0/config/reference_config_test.go

xmsz commented 3 years ago

你可以参照这个测试用例试试https://github.com/apache/dubbo-go/blob/3.0/config/reference_config_test.go

有没有简单一点的DEMO,因为刚学有点想先实现看看效果。普通调用没问题就是泛化没有完整DEMO不知道怎么跑,现在DEMO里的我跑不起来

现在遇到

panic: Failed to invoke the method $invoke. No provider available for the service dubbo://:@192.168.1.83:80/?interface=org.apache.dubbo.RankProvider&group=&version= from registry nacos://127.0.0.1:8848?group=&registry=nacos&registry.label=true&registry.preferred=false&registry.role=0&registry.timeout=&registry.ttl=&registry.weight=0&registry.zone=&simplified=false on the consumer 192.168.1.83 using the dubbo version 3.0.0 .Please check if the providers have been started and registered.
xmsz commented 3 years ago

然后我尝试设置一个url config.URL = "dubbo://127.0.0.1:8848"

调试信息变多了,但是还是没有执行方法

2021-08-11T10:46:49.471+0800    ERROR   dubbo/dubbo_codec.go:244    pkg.Unmarshal(len(@data):0) = error:illegal package!
github.com/apache/dubbo-go-hessian2.init

    getty/readwriter.go:60  pkg.Unmarshal(ss:&{name:client endPoint:0xc00021d4a0 Connection:0xc000219450 listener:0xc00020d390 reader:0xc0002082b0 writer:0xc0002082b0 maxMsgLen:102400 period:30000000000 wait:1000000000 once:0xc000212700 done:0xc000382300 attrs:0xc00020d380 grNum:2 rDone:0xc000382360 lock:{w:{state:0 sema:0} writerSem:0 readerSem:0 readerCount:0 readerWait:0}}, len(@data):590) = error:illegal package!
github.com/apache/dubbo-go-hessian2.init
 maybe the client read timeout or fail to decode tcp stream in Writer.Write
ChangedenCZD commented 3 years ago

我尝试补充dubbo-go-sample的实例

xmsz commented 3 years ago

我尝试补充dubbo-go-sample的实例

感恩!

ChangedenCZD commented 3 years ago

建议优先考虑使用配置文件的形式进行启动

xmsz commented 3 years ago

建议优先考虑使用配置文件的形式进行启动

ok 然后我用配置试了一下

result err: Failed to invoke the method $invoke. No provider available for the service dubbo://:@192.168.1.83:80/?interface=org.apache.dubbo.RankProvider&group=&version= from registry nacos://127.0.0.1:8848?group=&registry=nacos&registry.label=true&registry.preferred=false&registry.role=0&registry.timeout=3s&registry.ttl=10m&registry.weight=0&registry.zone=&simplified=false on the consumer 192.168.1.83 using the dubbo version 1.5.6 .Please check if the providers have been started and registered.

为什么会有@192.168.1.83:80/ 这个我要哪里设置

ChangedenCZD commented 3 years ago

原因是没有先启动相关的provider实例,可在对应的reference配置加check: false

references:
  "UserProvider":
    registry: "demoZk"
    protocol : "dubbo"
    interface : "org.apache.dubbo.UserProvider"
    cluster: "failover"
    check: false
    methods :
    - name: "GetUser"
      retries: 3
xmsz commented 3 years ago

我好像找到我大部分问题的所在了

我用的是dubbo3,但是我的samples的分支一直是master(2.0)。导致服务一直对不上

我再试一试

ChangedenCZD commented 3 years ago

我好像找到我大部分问题的所在了

我用的是dubbo3,但是我的samples的分支一直是master(2.0)。导致服务一直对不上

我再试一试

import (
    "context"
    "time"

    "dubbo.apache.org/dubbo-go/v3/config"
    gxlog "github.com/dubbogo/gost/log"

    _ "dubbo.apache.org/dubbo-go/v3/cluster/cluster_impl"

    _ "dubbo.apache.org/dubbo-go/v3/cluster/loadbalance"

    _ "dubbo.apache.org/dubbo-go/v3/common/proxy/proxy_factory"

    _ "dubbo.apache.org/dubbo-go/v3/filter/filter_impl"

    _ "dubbo.apache.org/dubbo-go/v3/registry/protocol"

    _ "dubbo.apache.org/dubbo-go/v3/registry/nacos"
)
xmsz commented 3 years ago

@ChangedenCZD 不好意思 我可能还是需要一个DEMO

dubbo-go3 + tri + protobuf + nacos +泛化

我现在还是没跑通

3.0 Sample里的generic DEMO,我本地能跑通,但是一改就崩 太难受了

LaurenceLiZhixin commented 3 years ago

@xavier-niu Pls follow up on this issue.

LaurenceLiZhixin commented 3 years ago

@xmsz You can join our dingtalk group:23331795 and discuss the problem together. I found a problem that, pb serialization service can't be generic invoked. I'm not sure which serialization type you choose in your server side.

ChangedenCZD commented 3 years ago

@ChangedenCZD 不好意思 我可能还是需要一个DEMO

dubbo-go3 + tri + protobuf + nacos +泛化

我现在还是没跑通

3.0 Sample里的generic DEMO,我本地能跑通,但是一改就崩 太难受了

补充了demo,您可以去protobuf-and-nacos-sample-prprotobuf-and-nacos-sample-code拉取相关代码,看看是否能解决您部分疑惑。

LaurenceLiZhixin commented 3 years ago

@xmsz Any feedback?

xmsz commented 3 years ago

@xmsz Any feedback?

最近没时间测了 我过段时间再反馈