Клиент RabbitMQ Java: почему JsonRpcServer не поддерживает большинство типов параметров метода?

У меня есть несколько методов, которые я хочу показать клиенту 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"
}

}

Когда я изменяю тип аргумента на String, он работает... И, похоже, он не принимает никаких других типов, кроме String и map. Даже Объекты не будут работать как аргумент.

Почему JsonRpcClient не принимает объекты?


Конфигурация:

Я использую Rabbit Mq JsonRPC клиент с загрузкой Spring. Моя конфигурация выглядит так:

@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;
}

Я использую это так:

@Autowired
private ProxyRpcBuilder rpcBuilder;
....
rpcBuilder.create(IRPCService.class).getById(commentId);

Мой прокси выглядит так:

@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);
    }
} ...

0 ответов

Другие вопросы по тегам