开发者

C++ RPC library suggestions [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 9 years ago.

I'm looking for suggestions regarding RPC libraries implemented in C++, for C++ developers.

Some requirements constraints:

  • Should work on both linux/unix and win32 systems
  • Be able to execute free function and class methods
  • Hopefully written in modern C++ not 90's/java-esque C++
  • Be able to function开发者_如何学C over networks and hetrogenous architectures
  • Not too slow or inefficient
  • Hopefully provide interfaces for TR1 style std::function's et al.

My example usage is to invoke the free function foo on a remote machine.

---snip---
// foo translation unit
int foo(int i, int j)
{
   return i + j;
}
---snip---


---snip---
// client side main
int main()
{
   //register foo on client and server
   //setup necassary connections and states

   int result;

   if (RPCmechanism.invoke("foo",4,9,result))
      std::cout << "foo(4,9) = " result << std::endl;
   else
      std::cout << "failed to invoke foo(4,9)!" << std::endl;

   return 0;
}
---snip---

Something that can achieve the above or similar would be great.

Note: I am NOT interested in other language bindings. Please do not proffer a solution because it has other language bindings. I'm only interested in well designed RPC frameworks written in C++ for the C++ language, that are efficient and appropriate for HPC scenarios.


That's quite a set of requirements...

While not meeting all of them (as I'm not sure that any such beast exists - I commend to your attention ICE from ZeroC. Developed in part by Michi Henning of CORBA fame (and ask your friends in telecom, that really isn't a dirty word), ICE is what CORBA would have looked like if it started later and wasn't developed by a committee.

Their C++ mapping is everything that CORBA is not, it uses STL types, and is generally newer feeling.

It fails the free-function and std::function tests, but given the improbability of finding a product for that entire list, this does a good job of many of the remainder.

Good Luck


I am also interested in viable C++ RPC implementations. After some research, I found that etch, thrift and protocol buffers are the most promising solutions, however none of them actually meets all my needs. My search criteria are:

  1. multi-language, with C++ and PHP as a must (C#, Java, Python, Perl are not so important right now)
  2. the server can compile/run only on Linux (with Windows as a long-term goal)
  3. the client must run on Windows and Linux (and possibly Mac)
  4. open source and commercial friendly (that is, no GPL)
  5. it must support encryption out of the box

And the candidates are:

  1. Apache Etch

    Pros:

    • the C binding is based on the APR
    • supports encryption
    • runs on both platforms

    Cons

    • slow development
    • lacks a PHP binding
  2. Apache Thrift

    Pros:

    • small
    • multiple language bindings

    Cons:

    • currently, it doesn't support encryption (under development, at least for the C++ binding)
    • on Windows, it requires Cygwin
  3. Protocol Buffers with an in-house developed RPC solution

    Pros:

    • small
    • multiple language bindings

    Cons:

    • no built-in RPC

Currently, I am evaluating the possibility to develop the RPC layer for Protobuf using APR.

However, search continues...

EDIT: I managed to work through some of these issues by using Apache Qpid (C++ version) with protobuf for serialization, although it currently lacks some features that I need.


old ones like DCE-RPC, CORBA,

or Protocol Buffers, or Thrift, Etch,

or web ones like SOAP, or REST.

Which one you want depends on what you want to do. eg. fast and efficient RPC for a local network would require a lightweight, binary RPC like Protocol Buffers, but a RPC for heterogenous web services would require the much more verbose SOAP.

Google uses PB for all its internal RPCs so it's a good choice. Facebook uses Thrift so its hardly a small player, and MS likes SOAP.


Have you tried thrift, http://thrift.apache.org/ ?


Check out FastRPC, http://fastrpc.sourceforge.net/ .


RCF looks to be what you want: http://www.deltavsoft.com/index.html


you can use protobuf implement one by yourself, and add all you wanted featrue. It is not too hard, and you can get many benefit from it.


The following code, pulled from an example TAO CORBA client, shows that 3 lines of code are required to connect to a server, and one line of code to call a function. Note that the function call looks like a native local function call. This can either be a free function, or a member function.

// Bring in the IOR
Object_var factory_object =  orb->string_to_object (argv[1]);

// Now downcast the object reference 
My_Factory_var factory = My_Factory::_narrow (factory_object.in ());

// Now get the full name and price of the other arguments:
Widget_var widget = factory->get_widget (argv[i]);

// Get its name, put it on a _var so it is automatically
// released!
String_var full_name = widget->full_name ();

// Now get the price
Double price = widget->price ();

cout << "The price of a widget in \""
  << full_name.in () << "\" is $"
  << price << endl;

The server code is a little more complex to show, but in CORBA, for what you are looking to do, mostly, you create an IDL interface, run it through the compiler, then fill in your app logic in the appropriate slot in the stub. So, your main code looks like the following:

// First initialize the ORB, that will remove some arguments...
ORB_var orb = ORB_init(argc, argv, "ORB" /* the ORB name, it can be anything! */);
Object_var poa_object = orb->resolve_initial_references("RootPOA");
PortableServer::POA_var poa = PortableServer::POA::_narrow(poa_object.in());
PortableServer::POAManager_var poa_manager = poa->the_POAManager();
poa_manager->activate();

// Create the servant
My_Factory_i my_factory_i;

// Activate it to obtain the object reference
My_Factory_var my_factory = my_factory_i._this();

// Put the object reference as an IOR string
String_var ior = orb->object_to_string (my_factory.in());
orb->run();

    // Now in your stub file generated by the idl compiler, 
    char * Widget_i::full_name (

  )
  ACE_THROW_SPEC ((
    ::CORBA::SystemException
  ))
{
  return "Some widget name";
}

::CORBA::Double Widget_i::price (

  )
  ACE_THROW_SPEC ((
    ::CORBA::SystemException
  ))
{
  return 1.25;
}

Have a look at This WikiBook for more references and examples

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜