Git Product home page Git Product logo

thrift-pool-client's Introduction

thrift-pool-client

thrift-pool-client

  • raw and type safe TServiceClient pool
  • Multi backend servers support
  • Backend servers replace on the fly
  • Backend route by hash or random
  • Failover and failback support

Get Started

mvn dependency

<dependency>
    <groupId>com.github.phantomthief</groupId>
    <artifactId>thrift-pool-client</artifactId>
    <version>1.0.0</version>
</dependency>

java code sample

public class ThriftMain {
	 public static void main(String[] args) throws TException {
	        // customize pool config
	        GenericKeyedObjectPoolConfig poolConfig = new GenericKeyedObjectPoolConfig();
	        // ... customize pool config here
	        // customize transport, while if you expect pooling the connection, you should use TFrameTransport.
	        Function<ThriftServerInfo, TTransport> transportProvider = new Function<ThriftServerInfo, TTransport>() {

				@Override
				public TTransport apply(ThriftServerInfo info) {
					// TODO Auto-generated method stub
					TSocket socket = new TSocket(info.getHost(), info.getPort());
		            return socket;
				}
	            
	        };

	        Function<List<ThriftServerInfo>, List<ThriftServerInfo>> addElementFunction =
			        new Function<List<ThriftServerInfo>, List<ThriftServerInfo>>() {
			          @Override
			          public List<ThriftServerInfo> apply(List<ThriftServerInfo> list) {
			        	  return Arrays.asList(//
					                ThriftServerInfo.of("192.168.1.44", 8080)//
					                // or you can return a dynamic result.
					                );
			          }
			        };
			        
	        Supplier<List<ThriftServerInfo>> list  = Suppliers.compose(addElementFunction, new Supplier<List<ThriftServerInfo>>(){

				@Override
				public List<ThriftServerInfo> get() {
					// TODO Auto-generated method stub
					return Arrays.asList(//
			                ThriftServerInfo.of("192.168.1.44", 8080)//
			                // or you can return a dynamic result.
			                );
				}});
	      
//		 System.out.println("list1 "+list.get());
//		 System.out.println("list2 "+list.get());
		 ThriftClient thriftClient = new ThriftClientImpl( list,new DefaultThriftConnectionPoolImpl(poolConfig, transportProvider));
		 System.out.println("######start");
		 System.out.println(thriftClient.iface(ArithmeticService.Client.class).add(1,99));
		 System.out.println("######end");
	 }
}

Special Thanks

perlmonk with his great team gives me a huge help. (https://github.com/PhantomThief/thrift-pool-client)

thrift-pool-client's People

Contributors

igool avatar

Watchers

James Cloos avatar zhangqs avatar  avatar

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.