Coder Social home page Coder Social logo

aatarasoff / spring-thrift-starter Goto Github PK

View Code? Open in Web Editor NEW
162.0 24.0 67.0 437 KB

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

License: MIT License

Java 100.00%
spring spring-boot spring-cloud-starter thrift spring-cloud

spring-thrift-starter's Introduction

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!

spring-thrift-starter's People

Contributors

aatarasoff avatar adyach avatar alekseigoremykin avatar driver733 avatar enrique-fernandez-polo avatar gitter-badger avatar jihor avatar lavcraft avatar matthew-gladyshev avatar salmondx avatar sergeevii123 avatar tobiasbales avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spring-thrift-starter's Issues

Still maintained?

Is this package still maintained?

We are looking into using something similar but would like to extend e.g. the collected metrics and I was curious if it made sense to trying to contribute or if simply forking might be the easier option.

LoggingThriftMethodInterceptor exception wrapping

Hi! I see that LoggingThriftMethodInterceptor wraps any exception into a TApplicationException in afterThrowing(), TApplicationException being a checked exception. I did a small refactoring of that class and have just left this code as it was. But now it's bothering me. If my callee code results in some runtime exception, the exception chain gets ugly: SomeRuntimeException -> TApplicationException -> java.lang.reflect.UndeclaredThrowableException: null (!) -> org.apache.thrift.transport.TTransportException: HTTP Response code: 406

Maybe it's worth changing the exception type to some runtime exception subclass? The problem is, all libthrift exceptions are checked.

NullPointerException in TLoadBalancerClient

Exception occurs when there is no service with such name in service registry.
Here:

HttpURLConnection iox = 
    (HttpURLConnection) new URL(this.loadBalancerClient.choose(serviceName)
        .getUri().toString() + path).openConnection();

loadBalancerClient.choose(serviceName) returns null.

https://github.com/aatarasoff/spring-thrift-starter/blob/60bab1f92fca926ade509a36961a468a62f4d3df/autoconfigure/src/main/java/info/developerblog/spring/thrift/transport/TLoadBalancerClient.java

New client bean registration logic doesn't work

Here you register bean with name, which is generated by getBeanName method.
But later get bean from context by simple type name.
This two names are different, that's why you don't use registered bean and anyway go to else case.
It brakes mocking client bean

Add hystrix support

Add optional hystrix wrapper around thrift service calls.
It'll be great if optional toObservable() method will exists during compile time (dont know how to implement in java, analogue of mixin in groovy and scala).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.