Sunny Agarwal
Sunny Agarwal

Reputation: 1491

apache thrift integration with spring framework

I am looking to use thrift for my web service calls. From what I've read so far from thrift documentation is that I'll have to write a thrift file containing my POJOs and services that I want to expose. This file then needs to be compiled using a thrift compiler to generate the Java classes. And then client and servers have to be written using these.

Is there a simpler way to achieve this (any annotation based or Spring framework integrations available)?

Upvotes: 3

Views: 6443

Answers (4)

Alexander Tarasov
Alexander Tarasov

Reputation: 31

You can use this project for integration between SpringBoot and Apache Thrift https://github.com/aatarasoff/spring-thrift-starter.

As it is described in README you simply connect starter and create your handler like if you are using @RestController:

@ThriftHandler("/api")
public class TGreetingServiceHandler implements TGreetingService.Iface {

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

Upvotes: 2

bsideup
bsideup

Reputation: 3063

I wrote an article about Spring Boot and Thrift integration with detailed explanation how to combine them together : ) You can find my article here:

Java.DZone: Building Microservices with Spring Boot and Apache Thrift.

In general, you should create Servlet bean like this:

@Bean
public TProtocolFactory tProtocolFactory() {
    return new TBinaryProtocol.Factory();
}

@Bean
public Servlet calculator(TProtocolFactory protocolFactory, CalculatorServiceHandler handler) {
    return new TServlet(new TCalculatorService.Processor<CalculatorServiceHandler>(handler), protocolFactory);
}

where TCalculatorService is your Thrift service

Upvotes: 3

Anonymous
Anonymous

Reputation: 1

The following project seems to work on it https://github.com/joshlong/spring-advanced-marhshallers-and-service-exporters/

Upvotes: 0

ducin
ducin

Reputation: 26437

Nope, there's no custom binding between spring and thrift. Once you've created your .thrift files, you will generate Java classes that will form the thrift communication layer.

For example, I've created a Java server that calls SQL over hibernate (this is one layer) and returns data over thrift (another layer). Unfortunately, there has to be some Java code that will process moving abstract data from one layer into another.

Upvotes: 3

Related Questions