<NME> ExampleServiceImpl.java
<BEF> package com.github.wenweihu86.raft.example.server.service.impl;

import com.github.wenweihu86.raft.example.server.ExampleStateMachine;
import com.github.wenweihu86.raft.example.server.service.ExampleMessage;
import com.github.wenweihu86.raft.example.server.service.ExampleService;
import com.github.wenweihu86.raft.RaftNode;
import com.github.wenweihu86.raft.proto.RaftMessage;
import com.github.wenweihu86.rpc.client.RPCClient;
import com.github.wenweihu86.rpc.client.RPCProxy;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.protobuf.util.JsonFormat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ExampleServiceImpl implements ExampleService {

    private static final Logger LOG = LoggerFactory.getLogger(ExampleServiceImpl.class);
    private static JsonFormat.Printer printer = JsonFormat.printer().omittingInsignificantWhitespace();

    private RaftNode raftNode;
    private ExampleStateMachine stateMachine;

    private static final Logger LOG = LoggerFactory.getLogger(ExampleServiceImpl.class);
    private static JsonFormat jsonFormat = new JsonFormat();

    }

    @Override
    public ExampleMessage.SetResponse set(ExampleMessage.SetRequest request) {
        ExampleMessage.SetResponse.Builder responseBuilder = ExampleMessage.SetResponse.newBuilder();
        // 如果自己不是leader，将写请求转发给leader
        if (raftNode.getLeaderId() <= 0) {
            responseBuilder.setSuccess(false);
        } else if (raftNode.getLeaderId() != raftNode.getLocalServer().getServerId()) {
            RPCClient rpcClient = raftNode.getPeerMap().get(raftNode.getLeaderId()).getRpcClient();
            ExampleService exampleService = RPCProxy.getProxy(rpcClient, ExampleService.class);
            ExampleMessage.SetResponse responseFromLeader = exampleService.set(request);
            responseBuilder.mergeFrom(responseFromLeader);
        } else {
            // 数据同步写入raft集群
            byte[] data = request.toByteArray();
            boolean success = raftNode.replicate(data, RaftMessage.EntryType.ENTRY_TYPE_DATA);
            responseBuilder.setSuccess(success);
        }

        ExampleMessage.SetResponse response = responseBuilder.build();
        try {
            LOG.info("set request, request={}, response={}", printer.print(request),
                    printer.print(response));
        } catch (InvalidProtocolBufferException ex) {
            ex.printStackTrace();
        }
        return response;
    }

    @Override
    public ExampleMessage.GetResponse get(ExampleMessage.GetRequest request) {
        ExampleMessage.GetResponse response = stateMachine.get(request);
        try {
            LOG.info("get request, request={}, response={}", printer.print(request),
                    printer.print(response));
        } catch (InvalidProtocolBufferException ex) {
            ex.printStackTrace();
        }
        return response;
    }

        ExampleProto.SetResponse.Builder responseBuilder = ExampleProto.SetResponse.newBuilder();
        // 如果自己不是leader，将写请求转发给leader
        if (raftNode.getLeaderId() <= 0) {
            responseBuilder.setSuccess(false);
        } else if (raftNode.getLeaderId() != raftNode.getLocalServer().getServerId()) {
            onLeaderChangeEvent();
            ExampleService exampleService = BrpcProxy.getProxy(leaderRpcClient, ExampleService.class);
            ExampleProto.SetResponse responseFromLeader = exampleService.set(request);
            responseBuilder.mergeFrom(responseFromLeader);
        } else {
            // 数据同步写入raft集群
            byte[] data = request.toByteArray();
            boolean success = raftNode.replicate(data, RaftProto.EntryType.ENTRY_TYPE_DATA);
            responseBuilder.setSuccess(success);
        }

        ExampleProto.SetResponse response = responseBuilder.build();
        LOG.info("set request, request={}, response={}", jsonFormat.printToString(request),
                jsonFormat.printToString(response));
        return response;
    }

    @Override
    public ExampleProto.GetResponse get(ExampleProto.GetRequest request) {
        ExampleProto.GetResponse response = stateMachine.get(request);
        LOG.info("get request, request={}, response={}", jsonFormat.printToString(request),
                jsonFormat.printToString(response));
        return response;
    }

}

<MSG> update rpc-java to brpc-java

<DFF> @@ -1,14 +1,13 @@
 package com.github.wenweihu86.raft.example.server.service.impl;
 
+import com.baidu.brpc.client.BrpcProxy;
+import com.baidu.brpc.client.RpcClient;
 import com.github.wenweihu86.raft.example.server.ExampleStateMachine;
-import com.github.wenweihu86.raft.example.server.service.ExampleMessage;
+import com.github.wenweihu86.raft.example.server.service.ExampleProto;
 import com.github.wenweihu86.raft.example.server.service.ExampleService;
 import com.github.wenweihu86.raft.RaftNode;
-import com.github.wenweihu86.raft.proto.RaftMessage;
-import com.github.wenweihu86.rpc.client.RPCClient;
-import com.github.wenweihu86.rpc.client.RPCProxy;
-import com.google.protobuf.InvalidProtocolBufferException;
-import com.google.protobuf.util.JsonFormat;
+import com.github.wenweihu86.raft.proto.RaftProto;
+import com.googlecode.protobuf.format.JsonFormat;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -18,7 +17,7 @@ import org.slf4j.LoggerFactory;
 public class ExampleServiceImpl implements ExampleService {
 
     private static final Logger LOG = LoggerFactory.getLogger(ExampleServiceImpl.class);
-    private static JsonFormat.Printer printer = JsonFormat.printer().omittingInsignificantWhitespace();
+    private static JsonFormat jsonFormat = new JsonFormat();
 
     private RaftNode raftNode;
     private ExampleStateMachine stateMachine;
@@ -29,42 +28,34 @@ public class ExampleServiceImpl implements ExampleService {
     }
 
     @Override
-    public ExampleMessage.SetResponse set(ExampleMessage.SetRequest request) {
-        ExampleMessage.SetResponse.Builder responseBuilder = ExampleMessage.SetResponse.newBuilder();
+    public ExampleProto.SetResponse set(ExampleProto.SetRequest request) {
+        ExampleProto.SetResponse.Builder responseBuilder = ExampleProto.SetResponse.newBuilder();
         // 如果自己不是leader，将写请求转发给leader
         if (raftNode.getLeaderId() <= 0) {
             responseBuilder.setSuccess(false);
         } else if (raftNode.getLeaderId() != raftNode.getLocalServer().getServerId()) {
-            RPCClient rpcClient = raftNode.getPeerMap().get(raftNode.getLeaderId()).getRpcClient();
-            ExampleService exampleService = RPCProxy.getProxy(rpcClient, ExampleService.class);
-            ExampleMessage.SetResponse responseFromLeader = exampleService.set(request);
+            RpcClient rpcClient = raftNode.getPeerMap().get(raftNode.getLeaderId()).getRpcClient();
+            ExampleService exampleService = BrpcProxy.getProxy(rpcClient, ExampleService.class);
+            ExampleProto.SetResponse responseFromLeader = exampleService.set(request);
             responseBuilder.mergeFrom(responseFromLeader);
         } else {
             // 数据同步写入raft集群
             byte[] data = request.toByteArray();
-            boolean success = raftNode.replicate(data, RaftMessage.EntryType.ENTRY_TYPE_DATA);
+            boolean success = raftNode.replicate(data, RaftProto.EntryType.ENTRY_TYPE_DATA);
             responseBuilder.setSuccess(success);
         }
 
-        ExampleMessage.SetResponse response = responseBuilder.build();
-        try {
-            LOG.info("set request, request={}, response={}", printer.print(request),
-                    printer.print(response));
-        } catch (InvalidProtocolBufferException ex) {
-            ex.printStackTrace();
-        }
+        ExampleProto.SetResponse response = responseBuilder.build();
+        LOG.info("set request, request={}, response={}", jsonFormat.printToString(request),
+                jsonFormat.printToString(response));
         return response;
     }
 
     @Override
-    public ExampleMessage.GetResponse get(ExampleMessage.GetRequest request) {
-        ExampleMessage.GetResponse response = stateMachine.get(request);
-        try {
-            LOG.info("get request, request={}, response={}", printer.print(request),
-                    printer.print(response));
-        } catch (InvalidProtocolBufferException ex) {
-            ex.printStackTrace();
-        }
+    public ExampleProto.GetResponse get(ExampleProto.GetRequest request) {
+        ExampleProto.GetResponse response = stateMachine.get(request);
+        LOG.info("get request, request={}, response={}", jsonFormat.printToString(request),
+                jsonFormat.printToString(response));
         return response;
     }
 

update rpc-java to brpc-java