object Thrift extends Client[ThriftClientRequest, Array[Byte]] with Server[Array[Byte], Array[Byte]]
Client and server for Apache Thrift.
Thrift implements Thrift framed transport and binary protocol by
default, though custom protocol factories (i.e. wire encoding) may
be injected with withProtocolFactory. The client,
Client[ThriftClientRequest, Array[Byte]] provides direct access
to the thrift transport, but we recommend using code generation
through either Scrooge or
a fork
of the Apache generator. A rich API is provided to support
interfaces generated with either of these code generators.
The client and server uses the standard thrift protocols, with support for both framed and buffered transports. Finagle attempts to upgrade the protocol in order to ship an extra envelope carrying additional request metadata, containing, among other things, request IDs for Finagle's RPC tracing facilities.
The negotiation is simple: on connection establishment, an improbably-named method is dispatched on the server. If that method isn't found, we are dealing with a legacy thrift server, and the standard protocol is used. If the remote server is also a finagle server (or any other supporting this extension), we reply to the request, and every subsequent request is dispatched with an envelope carrying trace metadata. The envelope itself is also a Thrift struct described here.
Clients
Clients can be created directly from an interface generated from a Thrift IDL:
For example, this IDL:
service TestService {
string query(1: string x)
}compiled with Scrooge, generates the interface
TestService.MethodPerEndpoint. This is then passed
into Thrift.Client.build:
Thrift.client.build[TestService.MethodPerEndpoint]( addr, classOf[TestService.MethodPerEndpoint])
However note that the Scala compiler can insert the latter
Class for us, for which another variant of build is
provided:
Thrift.client.build[TestService.MethodPerEndpoint](addr)
In Java, we need to provide the class object:
TestService.MethodPerEndpoint client =
Thrift.client.build(addr, TestService.MethodPerEndpoint.class);The client uses the standard thrift protocols, with support for both framed and buffered transports. Finagle attempts to upgrade the protocol in order to ship an extra envelope carrying trace IDs and client IDs associated with the request. These are used by Finagle's tracing facilities and may be collected via aggregators like Zipkin.
The negotiation is simple: on connection establishment, an improbably-named method is dispatched on the server. If that method isn't found, we are dealing with a legacy thrift server, and the standard protocol is used. If the remote server is also a finagle server (or any other supporting this extension), we reply to the request, and every subsequent request is dispatched with an envelope carrying trace metadata. The envelope itself is also a Thrift struct described here.
Servers
TestService.MethodPerEndpoint must be implemented and passed
into serveIface:
// An echo service ThriftMux.server.serveIface(":*", new TestService.MethodPerEndpoint { def query(x: String): Future[String] = Future.value(x) })
- Alphabetic
- By Inheritance
- Thrift
- Server
- Client
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
case class
Client(stack: Stack[ServiceFactory[ThriftClientRequest, Array[Byte]]] = Client.stack, params: Params = Client.params) extends StdStackClient[ThriftClientRequest, Array[Byte], Client] with WithSessionPool[Client] with WithDefaultLoadBalancer[Client] with WithThriftPartitioningStrategy[Client] with ThriftRichClient with Product with Serializable
A ThriftMux
com.twitter.finagle.Client.A ThriftMux
com.twitter.finagle.Client.- See also
Configuration documentation
Thrift documentation
Mux documentation
-
case class
Server(stack: Stack[ServiceFactory[Array[Byte], Array[Byte]]] = Server.stack, params: Params = Server.params) extends StdStackServer[Array[Byte], Array[Byte], Server] with ThriftRichServer with Product with Serializable
A ThriftMux
com.twitter.finagle.Server.A ThriftMux
com.twitter.finagle.Server.- See also
Configuration documentation
Thrift documentation
Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
- def client: Client
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
newClient(dest: Name, label: String): ServiceFactory[ThriftClientRequest, Array[Byte]]
- Definition Classes
- Thrift → Client
-
final
def
newClient(dest: String, label: String): ServiceFactory[ThriftClientRequest, Array[Byte]]
- Definition Classes
- Client
-
final
def
newClient(dest: String): ServiceFactory[ThriftClientRequest, Array[Byte]]
- Definition Classes
- Client
-
def
newService(dest: Name, label: String): Service[ThriftClientRequest, Array[Byte]]
- Definition Classes
- Thrift → Client
-
final
def
newService(dest: String, label: String): Service[ThriftClientRequest, Array[Byte]]
- Definition Classes
- Client
-
final
def
newService(dest: String): Service[ThriftClientRequest, Array[Byte]]
- Definition Classes
- Client
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
serve(addr: SocketAddress, service: ServiceFactory[Array[Byte], Array[Byte]]): ListeningServer
- Definition Classes
- Thrift → Server
-
final
def
serve(addr: String, service: Service[Array[Byte], Array[Byte]]): ListeningServer
- Definition Classes
- Server
-
final
def
serve(addr: String, service: ServiceFactory[Array[Byte], Array[Byte]]): ListeningServer
- Definition Classes
- Server
-
final
def
serve(addr: SocketAddress, service: Service[Array[Byte], Array[Byte]]): ListeningServer
- Definition Classes
- Server
-
def
serveAndAnnounce(name: String, service: Service[Array[Byte], Array[Byte]]): ListeningServer
- Definition Classes
- Server
-
def
serveAndAnnounce(name: String, service: ServiceFactory[Array[Byte], Array[Byte]]): ListeningServer
- Definition Classes
- Server
-
def
serveAndAnnounce(name: String, addr: String, service: Service[Array[Byte], Array[Byte]]): ListeningServer
- Definition Classes
- Server
-
def
serveAndAnnounce(name: String, addr: String, service: ServiceFactory[Array[Byte], Array[Byte]]): ListeningServer
- Definition Classes
- Server
-
def
serveAndAnnounce(name: String, addr: SocketAddress, service: Service[Array[Byte], Array[Byte]]): ListeningServer
- Definition Classes
- Server
-
def
serveAndAnnounce(name: String, addr: SocketAddress, service: ServiceFactory[Array[Byte], Array[Byte]]): ListeningServer
- Definition Classes
- Server
- def server: Server
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
- object Client extends ThriftClient with Serializable
- object Server extends Serializable
- object param