Skip to content

Set of cool annotations that helps you building Thrift applications with Spring Boot

License

Notifications You must be signed in to change notification settings

aatarasoff/spring-thrift-starter

Repository files navigation

Apache Thrift Starter for Spring Boot

Join the chat at https://gitter.im/aatarasoff/spring-thrift-starter Build Status

Set of cool annotations that helps you building Thrift applications with Spring Boot.

How to connect the project

repositories {
    ...
    maven {
        url = uri("https://maven.pkg.github.com/aatarasoff/spring-thrift-starter")
        credentials {
            username = System.getenv("USERNAME")
            password = System.getenv("TOKEN")
        }
    }
}

compile 'info.developerblog.spring.thrift:spring-thrift-starter:+'

For more information, please, look the official github packages documentation.

How to use this

Server-side

Annotation @ThriftController("servlet_path") helps you building server controller for request processing

@ThriftController("/api")
public class TGreetingServiceController implements TGreetingService.Iface {

    @Override
    public String greet(TName name) throws TException {
        // your logic
    }
}

Client-side

@ThriftClient

@ThriftClient(serviceId = "registered_service", (path) = "server_handler_path") helps you with multithreaded client with full Spring Cloud support.

@ThriftClient(serviceId = "greeting-service", path = "/api")
TGreetingService.Client client;

Beans

Thrift clients can also be used as regular beans

(which can be configured through app properties)

class Service {
    @Autowired
    private TGreetingService.Client client;
}
class Service {
    private final TGreetingService.Client client;
    @Autowired
    public Service(TGreetingService.Client client) {
        this.client = client;
    }
}

@ThriftClientsMap

@ThriftClientsMap(mapperClass) annotation helps to create a string-keyed map of clients for a set of services having the same interface, allowing to define the concrete callee instance at runtime:

@ThriftClientsMap(mapperClass = SampleMapper.class)
Map<String, TGreetingService.Client> clientsMap;

Mapper class requirements:

  • must extend AbstractThriftClientKeyMapper
  • must be registered as a bean in the application context

Thrift Client configuration

greeting-service:                     #service name
  endpoint: http://localhost:8080/api #direct endpoint
  ribbon:                             #manually ribbon
      listOfServers: localhost:8080
  path: /service                      #general path
  connectTimeout: 1000                #default=1000
  readTimeout: 10000                  #default=30000

thrift.client.max.threads: 10         #default=8

If you use service discovery backend (as Eureka or Consul) only path maybe needed.

See tests for better understanding.

Sleuth support

Since 1.0.0 starter have supported Spring Cloud Sleuth for tracing.

Special thanks to

Enjoy!