标签:thrift thrift使用实例 java thrift org.slf4j错误
namespace java com.nerd.thrift.service /** * */ service sayThriftService{ void say(); }通过在命令行中转到 thrift-1.8.0.exe -gen java sayThriftService
public class sayThriftService { /** * */ public interface Iface { public void say() throws org.apache.thrift.TException; } public interface AsyncIface { public void say(org.apache.thrift.async.AsyncMethodCallback<AsyncClient.say_call> resultHandler) throws org.apache.thrift.TException; } public static class Client extends org.apache.thrift.TServiceClient implements Iface { public static class Factory implements org.apache.thrift.TServiceClientFactory<Client> { public Factory() {} public Client getClient(org.apache.thrift.protocol.TProtocol prot) { return new Client(prot); } public Client getClient(org.apache.thrift.protocol.TProtocol iprot, org.apache.thrift.protocol.TProtocol oprot) { return new Client(iprot, oprot); } } ...................省略(具体看自己的生成代码)
package com.nerd.clq; import org.apache.thrift.TException; import org.apache.thrift.TProcessor; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocolFactory; import org.apache.thrift.server.TServer; import org.apache.thrift.server.TThreadPoolServer; import org.apache.thrift.server.TThreadPoolServer.Args; import org.apache.thrift.transport.TServerSocket; import com.nerd.clq.thrift.sayThriftService; import com.nerd.clq.thrift.sayThriftService.Iface; public class Server implements sayThriftService.Iface{ private static TServer server; @Override public void say() throws TException { System.out.println(System.currentTimeMillis()); } public static void main(String[] args) throws TException { Server server1 = new Server(); TServerSocket serverTransport = new TServerSocket(8080); TProtocolFactory proFactory = new TBinaryProtocol.Factory(); sayThriftService.Processor<Iface> processor = new sayThriftService.Processor<Iface>(server1); Args arg = new Args(serverTransport) { }.protocolFactory(proFactory).processor(processor); server = new TThreadPoolServer(arg); //启动服务(先启动这个类,然后启动client类) server.serve(); } }
package com.nerd.clq; import org.apache.thrift.TException; import org.apache.thrift.protocol.TBinaryProtocol; import org.apache.thrift.protocol.TProtocol; import org.apache.thrift.transport.TSocket; import org.apache.thrift.transport.TTransport; import com.nerd.clq.thrift.sayThriftService; public class Client { public static void main(String[] args) throws TException { TTransport transport = new TSocket("localhost", 8080); TProtocol protocol = new TBinaryProtocol(transport); sayThriftService.Client client = new sayThriftService.Client(protocol); transport.open(); client.say(); transport.close(); } }
标签:thrift thrift使用实例 java thrift org.slf4j错误
原文地址:http://blog.csdn.net/u012516914/article/details/37886099