I've a C++ application with multiple classes and I should make available their methods over a Thrift service using the same port.
Actually, according with documentation, the only way seems to create a single class using thrift generator that call other class methods.
Instead, I would like to directly use native class methods. Is it possible to create a service that supports multiple handlers/processors? Or multiple services on the same port?
P.S. I'm pretty new to Thrift.
Service multiplexing is implemented since 0.9.1. Look here for details and samples: https://issues.apache.org/jira/browse/THRIFT-563
Here's a link on related question: I'd like to use multiple services on one transport ( Thrift )
Related
I have a project which generates a puzzle and solves it in separate classes using the REPL. Is there any way to separate those classes into separate projects so that I can create a server that is on the same machine and can find puzzles already generated and return them to the calling client (puzzle solver) without the use of web servers?
Update: initially misunderstood what I was trying to do and reworded my question
Definitely you can. In broad strokes, you probably want:
A single project with clear client, server and shared namespaces (eg. logic about solving puzzles that might be shared between client and server). There's nothing intrinsically wrong about bundling all the code together at first (later you can ship client+shared and server+shared separately)
A library to make client/server communication simpler. A common use case is exposing the server with a web API because it's also simpler to test with web browsers, CLI clients (such as cURL), but it's OK if you want to use plain sockets and exchange messages in whatever format (EDN strings?) makes sense to you.
An example of a library for sockets would be https://github.com/atroche/clj-sockets , if you don't want to use Java interop and use classes from the java.net package directly.
Also note that web servers are actually socket servers too that listen for connections on fixed ports (eg. 80, 443 or 8080) for HTTP messages using certain conventions (eg. GET /api/puzzles/1)
Finally, you'll need at least two namespaces that export a -main method: one to launch the server and another to launch a client.
My application it's C++ service. And I need to add API for it. I consider that it will be XML/JSON RPC based API. How should I design a program for reusing existing code base and provide API.
I see following options:
My application will work via RPC layer. Seems that it's bad option due to low performance;
Before starting of service I will fork it and run my application in the first process and RPC server in the second; Seems ok, but how to restart RPC server in this case?
I guess there is a well known pattern for such issues.
Thanks.
If you can use a web server, then the FastCGI concept might be what you're looking for. One of the main duties of FastCGI is to allow you to put on a public API (from the web server) that internally calls the "real" application, in your case the resident C++ service. So all work is done at the web server to create the public API using any technology you wish, and little or no code changes done in your C++ service.
I am looking for a clean way to add service oriented access to an existing GWT application (client + RemoteService based server). The thing is that all the services are already in place, described by the #RemoteServiceRelativePath notation. It would be nice to be able to actually add the #WebService notation and have access to them both with RPC and XML/JSON/..
The real problem is that extending a current application to support other clients than the existing GWT one is a bit hard because of the GWT obfuscation. This also leads to an unneeded coupling between client and server since they both need to be deployed at the same time, because of the .gwt.rpc generated files.
I would like to reuse the existing RemoteService interfaces to define web services and connect to them with new clients via a plain-text protocol. Additionally, I would like to port the existing GWT client to the same protocol.
Is it possible to do this while using the same interfaces and implementation just by annotation?
What would be the best way to port the existing client to use a plain text protocol, RequestBuilder? Or just inject a new serialization implementation that does xml / json?
I don't even know where to start with this, this is why I'm asking. Maybe it is better to rewrite all the services and port everything at once but it will break everything until this is finished.
We've had a different approach since GWT the coupling of GWT between server and client side is not all bad but gives you a nice integration and you don't have to think too much about communication issues etc.
For that, our application had a frontend tier which consisted of the full gwt stack (client + server-coupling) and on the server-side, we connected via spring and RPC to the service layer.
On that way you can use on the benefits of spring and you don't loose the comfort of GWT.
But I Would like to hear if somebody already has gone other ways ;)
This is rather late and GWT is not the wonderchild it once was. However, for the sake of tying loose ends here's the solution I went for:
create a Java generator that parses all model (shared client/server classes) files through reflection and generates a Java file that reads/writes SOAP objects
bootstrap the above into a generic Java handler that handles native objects + array, sets, maps
write the service that can deal with the generated XML from the files above
It sounds a bit terse and a bit complicated but it 'only' took ~1 month to write the code to reliably convert >200 objects to their XML representation, automatically. The added benefit is that it allows mocking and cross-platform clients/servers.
As a summary, the generated code creates new methods 'fromXML' and 'toXML' that feed the fields that are public members (get/set) in the given class. So, given MyClass it would generate the MyClassSerializer and MyClassDeserializer Java classes that implement those SOAP-specific methods and also publish themselves to a 'dispatcher'. So whenever that dispatcher sees 'MyClass' it would know where to get the ser/deser functions from.
I would like to have a client connect to the server and determine what functions the process is accepting with the parameter and return types.
I'm already able to connect to a service and
The language I would like to do this in is C++.
Does the Thrift API allow provide a method for this?
Thanks.
I do not think general thrift allows for such querying, you need to have thrift idl files upfront and compile them.
If you can control server, you could have some querying layered a top of thrift.
I want to implement a adapter which can provide a universal interface to clients to use socket, opc, message queue, etc. In other words, it is a non-trivial job to learn to use the three above protocols' api.
For example, the client want to communicate with a external socket server, and the only thing he should do is to use our simple api rather than the complex bsd-socket's.
I want to know is there any existing implementation now which I can learn from. thanks!
ZeroMQ provides a socket like API that allows you to abstract away the transport mechanism. Currently it supports in process, shared memory, PGM, and TCP as transport mechanisms.
Google has protobuf, i think it's called, and there is another i've seen mentioned but it escapes me at the moment. Check here for information on protobuf