background: we have several apache httpd c++ servers running internally. UI will send request to one of the servers, then the main server will query many other internal servers to aggregate the result. It is one use case of rpc framework, which is more light weight than httpd. Our code is there, I just want to migrate our server to grpc.
Basic Ideas
Keep the main httpd server, which need to accept interal request from application/UI team. Once the httpd server get a message, it will use grpc to send to several protobug message to rpc servers, wait all the result, aggregate and finally return the response.
So I tried to create a client in httpd mod. Just add grpc things in our original code.
Install grpc and protobuf 3
install c++ version grpc. Protobuf 3 is needed. According to the instructions, when installing, it will detect if you already installed protobuf 3. If not, it will install protobuf in side third_party folder. We can also install some latest version of protobuf 3 by instructions
All kinds of errors
Test code is done. I ran into a lot of tricky problems.
compile error
|
|
Looks like the header files of apache httpd and grpc have a conflict.
That is because httpd has the code:
Meanwhile, grpc has the enum:
So that the compiler replace OK in grpc to 0, which equals 0 = 0 for grpc code:
solution:
Have to change httpd header file and recompile.
protobuf version error
protobuf higher version is not compatipable with low version, since the encode method may be changed.
error:
I installed grpc first, then install a newer version of protobuf v3.2.0. Noticed that in grpc repo, under third party folder, the version of protobug is 3.0.0. So for the safely use the solution is to reinstall protobuf v3.0.0 s(The same version used under somepath/grpc/third_party/protobuf
).
protobuf link error
Finally I ran into an unsolved problem.
The reason may be that according to the design of grpc, protobuf .so library cannot br loaded more than once. Some people said to link rpc and protobuf static library.
But in my project, due the makefile and the code infrustructure, cannot make it out.
This may be why in ORC Client c++, which also uses protobuf, protobuf is lined in .a.