sofastack / sofa-jraft

A production-grade java implementation of RAFT consensus algorithm.
https://www.sofastack.tech/projects/sofa-jraft/
Apache License 2.0
3.53k stars 1.12k forks source link

如何使用一个端口同时启用rheakvstore和rpcserver #1034

Closed daodol closed 8 months ago

daodol commented 8 months ago

可以在架构图中看到rheakvstore中已经使用到RPC的功能了,但是没找到通过rheakvstore发起rpc的方法。现在我是同时启用了store的集群和rpc的集群,但是这样使用感觉很怪,有没有更好的办法

fengjiachun commented 8 months ago

可以参考下这里:https://github.com/sofastack/sofa-jraft/tree/master/jraft-example/src/main/java/com/alipay/sofa/jraft/example/rheakv

daodol commented 8 months ago

可以参考下这里:https://github.com/sofastack/sofa-jraft/tree/master/jraft-example/src/main/java/com/alipay/sofa/jraft/example/rheakv

这个貌似只有RheaKVStore啊,RPC怎么调

daodol commented 8 months ago

hello?

fengjiachun commented 8 months ago

RheaKVStore 就是一个 client 阿,它不就是通过 rpc 调用得吗

daodol commented 8 months ago

RheaKVStore 就是一个 client 阿,它不就是通过 rpc 调用得吗

对啊,但是我不能用client把消息写进store,另一端监听store来实现调用响应把,这能行?。store是通过rpc调用的,但是没找到RPC其他功能对应的接口啊

fengjiachun commented 8 months ago

get 意思了,是想复用 rpc server 对吧? reeakv server 启动后,从 StoreEngine 可以拿到 getRpcServer(),看看行不行呢?jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/StoreEngine.java

daodol commented 8 months ago

get 意思了,是想复用 rpc server 对吧? reeakv server 启动后,从 StoreEngine 可以拿到 getRpcServer(),看看行不行呢?jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/StoreEngine.java

ok,非常感谢

daodol commented 8 months ago

get 意思了,是想复用 rpc server 对吧? reeakv server 启动后,从 StoreEngine 可以拿到 getRpcServer(),看看行不行呢?jraft-rheakv/rheakv-core/src/main/java/com/alipay/sofa/jraft/rhea/StoreEngine.java

image 你好,通过StoreEngine可以找到rpcServer,但是我通过这种方式提示序列化失败,也没有找到设置序列化方式的地方 报错: com.alipay.remoting.exception.SerializationException: Exception caught when serialize content of rpc request command! Exception caught when serialize content of rpc request command! Serialized class com.alipay.sofa.jraft.rpc.RpcRequests$PingRequest$Builder must implement java.io.Serializable

fengjiachun commented 8 months ago

你的参数是 PingRequestBuilder 而不是 PingRequest, 需要调用一下 build() 阿

daodol commented 8 months ago

你的参数是 PingRequestBuilder 而不是 PingRequest, 需要调用一下 build() 阿

好吧谢谢。这种方式怎么自定义序列化和反序列化,比如使用hessian

fengjiachun commented 8 months ago

jraft 通信层是基于 SPI 可扩展的,目前支持两种 rpc 框架,分别是 bolt 和 gRPC :

  1. 使用 gRPC 通信,无法自定义序列化,似乎只能用 protobuf
  2. 使用 bolt,可以使用 bolt 的 CustomSerializerManager.registerCustomSerializer() 来自定义