finagle-clojure.thrift

Functions for creating Thrift clients & servers from Java classes generated from a Thrift service definition using Scrooge.

The lein-finagle-clojure plugin can be used to compile Thrift definitions to Java with Scrooge.

See: * test/clj/finagle_clojure/thrift_test.clj * https://github.com/samn/finagle-clojure-examples/tree/master/dog-breed-info

announce

(announce path server)

Announce this server to the configured load balancer.

This functions the same as announce* but returns the server passed in so it can be chained together like:

(->> service
     (thrift/serve ":9999")
     (thrift/announce "zk!localhost!/path/to/nodes")
     (f/await))

Arguments: * path: a String represent the path on the load balancer * server: a ListeningServer (returned by [serve])

Returns:

server

See: announce*, [https://twitter.github.io/finagle/guide/Names.html]

announce*

(announce* path server)

Announce this server to the configured load balancer.

Arguments: * path: a String representing the path on the load balancer * server: a ListeningServer (returned by [serve])

Returns:

A Future[Announcement].

See: announce, [https://twitter.github.io/finagle/guide/Names.html]

client

macro

(client addr client-iterface-class)

Sugar for creating a client for a compiled Thrift service. The appropriate Finagle interface for that class will automatically be imported. Note that operations on this client will return a Future representing the result of an call This is meant to show that this client can make an RPC call and may be expensive to invoke.

E.g. if a Thrift service definition has a method called doStuff you can call it on a client like this (.doStuff client).

Arguments:

  • addr: Where to find the Thrift server.
  • qualified-service-class-name: This class’s Finagled interface will automatically be imported. e.g. if you pass MyService then MyService$ServiceIface will be imported and used.

Returns:

A new client.

client-tls

macro

(client-tls addr client-interface-class ssl-ctx)

Sugar for creating a TLS-enabled client for a compiled Thrift service where the server has TLS enabled. You must use this client for TLS enabled servers.

The appropriate Finagle interface for that class will automatically be imported. Note that operations on this client will return a Future representing the result of an call This is meant to show that this client can make an RPC call and may be expensive to invoke.

E.g. if a Thrift service definition has a method called doStuff you can call it on a client like this (.doStuff client).

Arguments:

  • addr: Where to find the Thrift server.
  • qualified-service-class-name: This class’s Finagled interface will automatically be imported. e.g. if you pass MyService then MyService$ServiceIface will be imported and used.

Returns:

A new client.

insecure-ssl-context

(insecure-ssl-context)

Returns a naive SSLContext that provides no certificate verification.

THIS SHOULD ONLY BE USED FOR TESTING.

serve

(serve addr service)

Serve service on addr. Use this to actually run your Thrift service. Note that this will not block while serving. If you want to wait on this use finagle-clojure.futures/await.

Arguments:

  • addr: The port on which to serve.
  • service: The Service that should be served.

Returns:

A new com.twitter.finagle.ListeningServer.

serve-tls

(serve-tls addr service & opts)

Serve service on addr over TLS. Use this to actually run your Thrift Service. Note that this will not block while serving. If you want to wait on this use finagle-clojure.futures/await.

Arguments:

  • addr: The port on which to serve.
  • service: The Service that should be served.
  • opts: key/value options for the server, includes:
    • :priv: (required) fully qualified file name for the private key in PEM format used for running the server
    • :pub: (required) fully qualified file name for the public key in PEM format used for running the server

Returns:

A new com.twitter.finagle.ListeningServer.

service

macro

(service service-class-name & body)

Sugar for implementing a com.twitter.finagle.Service based on the interface defined in qualified-service-class-name. The appropriate Finagle interface for that class will automatically be imported. Provide an implementation for it like proxy (this is an implicit argument).

The Finagle interface for a Service class generated by Scrooge will wrap the response type of a method in Future so it is asynchronous.

Arguments:

  • qualified-service-class-name: This class’s Finagled interface will automatically be imported. e.g. if you pass MyService then MyService$ServiceIface will be imported and used.
  • body: the implementation of this service. Methods should be defined without an explicit this argument.

Returns:

A new Service.