RabbitMQ Java客户端:为什么JsonRpcServer不允许大多数方法参数类型?

RabbitMQ Java客户端:为什么JsonRpcServer不允许大多数方法参数类型?,java,rabbitmq,rpc,json-rpc,Java,Rabbitmq,Rpc,Json Rpc,我有一些方法想通过JsonRpcServer为客户端公开: Map getById(Long o); 每当我尝试使用此方法时,都会引发运行时异常: Caused by: com.rabbitmq.tools.jsonrpc.JsonRpcException: { "code": 500, "name": "JSONRPCError", "message": "Internal Server Error", "error": { "localizedMessage": "argu

我有一些方法想通过
JsonRpcServer
为客户端公开:

    Map getById(Long o);
每当我尝试使用此方法时,都会引发运行时异常:

Caused by: com.rabbitmq.tools.jsonrpc.JsonRpcException: {
"code": 500,
"name": "JSONRPCError",
"message": "Internal Server Error",
"error": {
    "localizedMessage": "argument type mismatch",
    "cause": null,
    "stackTrace": [{
        "fileName": "NativeMethodAccessorImpl.java",
        "nativeMethod": true,
        "methodName": "invoke0",
        "className": "sun.reflect.NativeMethodAccessorImpl",
        "lineNumber": -2
    }, {
        "fileName": "NativeMethodAccessorImpl.java",
        "nativeMethod": false,
        "methodName": "invoke",
        "className": "sun.reflect.NativeMethodAccessorImpl",
        "lineNumber": 62
    }, {
        "fileName": "DelegatingMethodAccessorImpl.java",
        "nativeMethod": false,
        "methodName": "invoke",
        "className": "sun.reflect.DelegatingMethodAccessorImpl",
        "lineNumber": 43
    }, {
        "fileName": "Method.java",
        "nativeMethod": false,
        "methodName": "invoke",
        "className": "java.lang.reflect.Method",
        "lineNumber": 483
    }, {
        "fileName": "JsonRpcServer.java",
        "nativeMethod": false,
        "methodName": "doCall",
        "className": "com.rabbitmq.tools.jsonrpc.JsonRpcServer",
        "lineNumber": 143
    }, {
        "fileName": "JsonRpcServer.java",
        "nativeMethod": false,
        "methodName": "handleStringCall",
        "className": "com.rabbitmq.tools.jsonrpc.JsonRpcServer",
        "lineNumber": 103
    }, {
        "fileName": "StringRpcServer.java",
        "nativeMethod": false,
        "methodName": "handleCall",
        "className": "com.rabbitmq.client.StringRpcServer",
        "lineNumber": 48
    }, {
        "fileName": "RpcServer.java",
        "nativeMethod": false,
        "methodName": "handleCall",
        "className": "com.rabbitmq.client.RpcServer",
        "lineNumber": 176
    }, {
        "fileName": "RpcServer.java",
        "nativeMethod": false,
        "methodName": "handleCall",
        "className": "com.rabbitmq.client.RpcServer",
        "lineNumber": 163
    }, {
        "fileName": "RpcServer.java",
        "nativeMethod": false,
        "methodName": "processRequest",
        "className": "com.rabbitmq.client.RpcServer",
        "lineNumber": 149
    }, {
        "fileName": "RpcServer.java",
        "nativeMethod": false,
        "methodName": "mainloop",
        "className": "com.rabbitmq.client.RpcServer",
        "lineNumber": 115
    }, {
        "fileName": "RabbitConfiguration.java",
        "nativeMethod": false,
        "methodName": "lambda$jsonRpcServer$0",
        "className": "com.ofaly.comments.RabbitConfiguration",
        "lineNumber": 56
    }, {
        "fileName": null,
        "nativeMethod": false,
        "methodName": "run",
        "className": "com.ofaly.comments.RabbitConfiguration$$Lambda$7\/82172068",
        "lineNumber": -1
    }, {
        "fileName": "Thread.java",
        "nativeMethod": false,
        "methodName": "run",
        "className": "java.lang.Thread",
        "lineNumber": 745
    }],
    "suppressed": [],
    "message": "argument type mismatch"
}
}

当我将参数的类型更改为字符串时,它会工作。。。除了字符串和映射之外,它似乎不接受任何其他类型。即使对象也不能用作参数

为什么JsonRpcClient不接受对象


配置:

我正在使用带有Spring引导的Rabbit Mq JsonRPC客户端。 我的配置如下所示:

@Value("${spring.rabbitmq.host}")
private String rabbitmqHost;

@Value("${spring.rabbitmq.queue}")
private String rabbitmqQueue;

private final IRPCService rpcService;

public RabbitConfiguration(final IRPCService rpcService) {
    this.rpcService = rpcService;
}

@Bean
public Connection rabbitmqConnection() throws IOException, TimeoutException {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(rabbitmqHost);
    return factory.newConnection();
}

@Bean
public Channel rpcChanel() throws IOException, TimeoutException {
    Connection connection = rabbitmqConnection();
    Channel channel = connection.createChannel();
    channel.queueDeclare(rabbitmqQueue, false, false, false, null);
    return channel;
}

@Bean
@Lazy(false)
public JsonRpcServer jsonRpcServer() throws IOException, TimeoutException {
    JsonRpcServer jsonRpcServer = new JsonRpcServer(rpcChanel(), rabbitmqQueue, IRPCService.class, rpcService);
    new Thread(() -> {
        try {
            jsonRpcServer.mainloop();
        } catch (Exception e) {
            System.out.println(e);
        }
    }).start();
    return jsonRpcServer;
}
@Component
public class ProxyRpcBuilder {

@Value("${spring.rabbitmq.queue}")
private String rabbitmqQueue;

private final Channel channel;
private JsonRpcClient jsonRpcClient;

public ProxyRpcBuilder(Channel channel) {
    this.channel = channel;
}

public <T> T create(Class<T> t) {
    try {
        if (jsonRpcClient == null) {
            jsonRpcClient = new JsonRpcClient(channel, "", rabbitmqQueue, 20000);
        }
        return (T) jsonRpcClient.createProxy(t);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
} ...
我这样使用它:

@Autowired
private ProxyRpcBuilder rpcBuilder;
....
rpcBuilder.create(IRPCService.class).getById(commentId);
我的代理看起来是这样的:

@Value("${spring.rabbitmq.host}")
private String rabbitmqHost;

@Value("${spring.rabbitmq.queue}")
private String rabbitmqQueue;

private final IRPCService rpcService;

public RabbitConfiguration(final IRPCService rpcService) {
    this.rpcService = rpcService;
}

@Bean
public Connection rabbitmqConnection() throws IOException, TimeoutException {
    ConnectionFactory factory = new ConnectionFactory();
    factory.setHost(rabbitmqHost);
    return factory.newConnection();
}

@Bean
public Channel rpcChanel() throws IOException, TimeoutException {
    Connection connection = rabbitmqConnection();
    Channel channel = connection.createChannel();
    channel.queueDeclare(rabbitmqQueue, false, false, false, null);
    return channel;
}

@Bean
@Lazy(false)
public JsonRpcServer jsonRpcServer() throws IOException, TimeoutException {
    JsonRpcServer jsonRpcServer = new JsonRpcServer(rpcChanel(), rabbitmqQueue, IRPCService.class, rpcService);
    new Thread(() -> {
        try {
            jsonRpcServer.mainloop();
        } catch (Exception e) {
            System.out.println(e);
        }
    }).start();
    return jsonRpcServer;
}
@Component
public class ProxyRpcBuilder {

@Value("${spring.rabbitmq.queue}")
private String rabbitmqQueue;

private final Channel channel;
private JsonRpcClient jsonRpcClient;

public ProxyRpcBuilder(Channel channel) {
    this.channel = channel;
}

public <T> T create(Class<T> t) {
    try {
        if (jsonRpcClient == null) {
            jsonRpcClient = new JsonRpcClient(channel, "", rabbitmqQueue, 20000);
        }
        return (T) jsonRpcClient.createProxy(t);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
} ...
@组件
公共类ProxyRpcBuilder{
@值(${spring.rabbitmq.queue}”)
私有字符串rabbitmqQueue;
专用最终通道;
私有JsonRpcClient JsonRpcClient;
公共ProxyRpcBuilder(频道){
this.channel=channel;
}
公共T创建(类T){
试一试{
if(jsonRpcClient==null){
jsonRpcClient=新的jsonRpcClient(通道“”,rabbitmqQueue,20000);
}
return(T)jsonRpcClient.createProxy(T);
}捕获(例外e){
抛出新的运行时异常(e);
}
} ...

我也有同样的问题。根据我的测试,
JsonRpcServer
只允许暴露参数为以下类型的方法:(1)基元类型,(2)
String
,(3)
List
,(4)
Map
。对我来说,它也适用于
Integer
Double
,但不适用于
Long
。另一方面,该方法的返回类型可以是任何类型的对象,并且可以工作。我也有同样的问题。根据我的测试,
JsonRpcServer
只允许公开参数如下的方法:以下类型:(1)基元类型,(2)
String
,(3)
List
,(4)
Map
。对我来说,它也适用于
Integer
Double
,但不适用于
Long
。另一方面,该方法的返回类型可以是任何类型的对象,它也可以工作。