Question

I use Apache Thrift to define a protocol. I would like the client to receive asynchronous messages from the server.

service ServerService {
    oneway void async_server_hello(1: string message_from_client);
    string sync_server_hello(1: string message_from_client);
}

service ClientService { // how to use it from the server side?
    oneway void async_client_hello(1: string message_from_server);
}

I know how to connect to the server, send sync and async messages to the server, but I don't know how to send async messages from the server to the connected client.

(Python or Erlang code is preferable, but any other language will do)

Was it helpful?

Solution

Bidi-messaging is not possible with Apache Thrift. The server always reacts on client requests (except for oneway, of course). If you want the server to call the client back, the client has to set up an server on it's own. Another option could be long-running calls to simulate the desired behaviour.

I have seen at least one fork on Github doing Bidi-Messaging, but

  • I don't know what the state of this/these project(s) is, and
  • that stuff is not part of the Apache Thrift project.

There are a bunch of JIRA tickets dealing with this topic, the essence is however that Thrift will not support this in near future, because one of the goals is simplicity, which Bidi is not per se, esepcially across transports and languages.

So there are solutions, but no built-in way that will do this automatically for you.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top