------------
Dubbo-Go端:
model/models.go
package model
import (
"context"
"fmt"
"time"
)
type DataSource struct {
Id int `hessian:"id"`
UserId int `hessian:"userId"`
UserName string `hessian:"userName"`
Name string `hessian:"name"`
Note string `hessian:"note"`
Type string `hessian:"type"` // Mapped from Java enum
ConnectionParams string `hessian:"connectionParams"`
CreateTime time.Time `hessian:"createTime"`
UpdateTime time.Time `hessian:"updateTime"`
FromType string `hessian:"fromType"`
}
// JavaClassName returns the fully qualified class name of the Java class.
func (d *DataSource) JavaClassName() string {
return "org.xxx.dao.entity.DataSource"
}
func (d DataSource) String() string {
return fmt.Sprintf("DataSource{ID: %d, UserID: %d, UserName: %s, Name: %s, Note: %s, Type: %s, ConnectionParams: %s, CreateTime: %v, UpdateTime: %v, FromType: %s}",
d.Id, d.UserId, d.UserName, d.Name, d.Note, d.Type, d.ConnectionParams, d.CreateTime, d.UpdateTime, d.FromType)
}
// DataSourceService is the interface for the DataSource service
type DataSourceService struct {
QueryDataSource func(ctx context.Context, id int) (*DataSource, error) `dubbo:"queryDataSource"`
}
main.go代码如下:
package main
import (
"Dubbo-Go/model"
"context"
"dubbo.apache.org/dubbo-go/v3/config"
_ "dubbo.apache.org/dubbo-go/v3/imports" // 导入dubbo-go需要的所有默认包
hessian "github.com/apache/dubbo-go-hessian2"
"github.com/dubbogo/gost/log/logger"
)
var (
dataSourceService = &model.DataSourceService{}
)
func main() {
hessian.RegisterPOJO(&model.DataSource{})
config.SetConsumerService(dataSourceService)
err := config.Load()
if err != nil {
panic(err)
}
logger.Infof("\n\ntest")
test()
}
func test() {
logger.Infof("开始测试调用 queryDataSource 方法")
id := 1
logger.Infof("即将调用 queryDataSource, ID: %d", id)
dataSources1, err := dataSourceService.QueryDataSource(context.TODO(), id)
if err != nil {
logger.Errorf("调用 queryDataSource 失败: %v", err)
}
logger.Infof("response result: %v", dataSources1)
}
dubbogo.yml文件如下:
dubbo:
registries:
nacos:
protocol: nacos
timeout: 60s
address: nacos://10.1.5.230:8848
namespace: dubbogo
username: nacos
password: nacos
protocols:
"dubbo":
name: "dubbo"
port: 20010
address: 10.1.5.175
consumer:
references:
DataSourceService:
protocol: dubbo
interface: org.xxx.api.service.DataSourceService
retries: 6
timeout: 6000
logger:
zap-config:
level: info
### Logs
在执行go run main.go之后,Go端报错如下:
2024-08-22T16:49:56.275+0800 INFO Dubbo-Go/main.go:34 开始测试调用 queryDataSource 方法
2024-08-22T16:49:56.275+0800 INFO Dubbo-Go/main.go:39 即将调用 queryDataSource, ID: 1
2024-08-22T16:49:56.276+0800 INFO impl/codec.go:169 response with exception: {SerialID:2 Type:36 ID:4 BodyLen:1085 ResponseStatus:40}
2024-08-22T16:49:56.277+0800 INFO impl/codec.go:169 response with exception: {SerialID:2 Type:36 ID:6 BodyLen:1085 ResponseStatus:40}
2024-08-22T16:49:56.278+0800 WARN proxy/proxy.go:212 [CallProxy] received rpc err: Failed to invoke the method queryDataSource in the service org.xxx.api.service.DataSourceService. Tried 1 times of the providers [dubbo://:@10.1.5.175:20010/?interface=org.xxx.api.service.DataSourceService&group=&version= dubbo://:@10.1.5.175:20010/?interface=org.xxx.api.service.DataSourceService&group=&version=] (2/1)from the registry service-discovery-registry://nacos:nacos@10.1.5.230:8848?registry=nacos®istry.group=®istry.label=true®istry.namespace
=dubbogo®istry.preferred=false®istry.role=0®istry.timeout=60s®istry.ttl=15m®istry.weight=0®istry.zone=&remote-client-name=dubbo.registries-nacos-10.1.5.230%3A8848&simplified=false on the consumer 192.168.146.1 using the dubbo version 3.0.4. Last error is java exception:Fail to decode request due to: java.lang.IllegalArgumentException: Service not found:org.xxx.api.service.DataSourceService, queryDataSource
java.lang.IllegalArgumentException: Service not found:org.xxx.api.service.DataSourceService, queryDataSource
at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:204)
at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:92)
at org.apache.dubbo.remoting.transport.DecodeHandler.decode(DecodeHandler.java:60)
at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:44)
at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:59)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.dubbo.common.threadlocal.InternalRunnable.run(InternalRunnable.java:41)
at java.lang.Thread.run(Thread.java:750)
.: java exception:Fail to decode request due to: java.lang.IllegalArgumentException: Service not found:org.xxx.api.service.DataSourceService, queryDataSource
java.lang.IllegalArgumentException: Service not found:org.xxx.api.service.DataSourceService, queryDataSource
at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:204)
at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:92)
at org.apache.dubbo.remoting.transport.DecodeHandler.decode(DecodeHandler.java:60)
at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:44)
at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:59)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.dubbo.common.threadlocal.InternalRunnable.run(InternalRunnable.java:41)
at java.lang.Thread.run(Thread.java:750)
2024-08-22T16:49:56.278+0800 ERROR Dubbo-Go/main.go:42 调用 queryDataSource 失败: java exception:Fail to decode request due to: java.lang.IllegalArgumentException: Service not found:org.xxx.api.service.DataSourceService, queryDataSource
java.lang.IllegalArgumentException: Service not found:org.xxx.api.service.DataSourceService, queryDataSource
at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:204)
at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:92)
at org.apache.dubbo.remoting.transport.DecodeHandler.decode(DecodeHandler.java:60)
at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:44)
at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:59)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.dubbo.common.threadlocal.InternalRunnable.run(InternalRunnable.java:41)
at java.lang.Thread.run(Thread.java:750)
main.test
E:/GoCode/Dubbo-Go/main.go:42
main.main
E:/GoCode/Dubbo-Go/main.go:29
runtime.main
D:/GO/src/runtime/proc.go:250
2024-08-22T16:49:56.279+0800 INFO Dubbo-Go/main.go:44 response result: DataSource{ID: 0, UserID: 0, UserName: , Name: , Note: , Type: , ConnectionParams: , CreateTime: 0001-01-01 00:00:00 +0000 UTC, UpdateTime: 0001-01-01 00:00:00 +0000 UTC, FromType: }
我的java端日志如下:
[WARN] 2024-08-22 16:49:56.281 +0800 org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation:[95] - [DUBBO] Decode rpc invocation failed: Service not found:org.xxx.api.service.DataSourceService, queryDataSource, dubbo version: 3.0.14, current host: 10.1.5.175
java.lang.IllegalArgumentException: Service not found:org.xxx.api.service.DataSourceService, queryDataSource
at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:204)
at org.apache.dubbo.rpc.protocol.dubbo.DecodeableRpcInvocation.decode(DecodeableRpcInvocation.java:92)
at org.apache.dubbo.remoting.transport.DecodeHandler.decode(DecodeHandler.java:60)
at org.apache.dubbo.remoting.transport.DecodeHandler.received(DecodeHandler.java:44)
at org.apache.dubbo.remoting.transport.dispatcher.ChannelEventRunnable.run(ChannelEventRunnable.java:59)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.dubbo.common.threadlocal.InternalRunnable.run(InternalRunnable.java:41)
at java.lang.Thread.run(Thread.java:750)
[INFO] 2024-08-22 16:49:56.293 +0800 org.apache.dubbo.remoting.transport.netty4.NettyServerHandler:[90] - [DUBBO] The connection of /10.1.5.175:59577 -> /10.1.5.175:20010 is disconnected., dubbo version: 3.0.14, current host: 10.1.5.175
[INFO] 2024-08-22 16:49:56.293 +0800 org.apache.dubbo.remoting.transport.netty4.NettyServerHandler:[90] - [DUBBO] The connection of /10.1.5.175:59579 -> /10.1.5.175:20010 is disconnected., dubbo version: 3.0.14, current host: 10.1.5.175
[WARN] 2024-08-22 16:49:56.293 +0800 org.apache.dubbo.remoting.transport.AbstractServer:[182] - [DUBBO] All clients has disconnected from /10.1.5.175:20010. You can graceful shutdown now., dubbo version: 3.0.14, current host: 10.1.5.175
[INFO] 2024-08-22 16:49:56.293 +0800 org.apache.dubbo.remoting.transport.netty4.NettyServerHandler:[90] - [DUBBO] The connection of /10.1.5.175:59578 -> /10.1.5.175:20010 is disconnected., dubbo version: 3.0.14, current host: 10.1.5.175
具体情况如上:这个报错查阅相关资料后,能力有限,依旧是无法解决java.lang.IllegalArgumentException: Service not found:org.xxx.api.service.DataSourceService, queryDataSource
Environment
Issue description
我参考这个官网学习java-server和go-client互通。https://cn.dubbo.apache.org/zh-cn/overview/mannual/golang-sdk/tutorial/develop/interflow/call_java/
java侧:org/xxx/dao/entity/DataSource.java部分代码如下: package org.xxx.dao.entity; ... import java.io.Serializable; import java.util.Date;
public class DataSource implements Serializable { private int id; private int userId; private String userName; private String name; private String note; private DbType type; private String connectionParams; private Date createTime; private Date updateTime; private String fromType;
}
org.xxx.api.service.DataSourceService.java部分代码如下: package org.xxx.api.service; ... import org.xxx.dao.entity.DataSource; ... import java.net.UnknownHostException; import java.util.List; import java.util.Map;
public interface DataSourceService { ... Map<String, Object> queryDataSource(int id); ... }
代码中也有DataSourceService的实现类DataSourceServiceImpl.java,代码不做赘述 dubbo-provider.xml的配置如下: