你好,调用user-thrift-service和message-service都是差不多的写法呀:
public UserService.Client getUserService() {
return getService(serverIp, serverPort, ServiceType.USER);
}
public MessageService.Client getMessasgeService() {
return getService(messageServerIp, messageServerPort, ServiceType.MESSAGE);
}
public T getService(String ip, int port, ServiceType serviceType) {
TSocket socket = new TSocket(ip, port, 3000);
TTransport transport = new TFramedTransport(socket);
try {
transport.open();
} catch (TTransportException e) {
e.printStackTrace();
return null;
}
TProtocol protocol = new TBinaryProtocol(transport);
TServiceClient result = null;
switch (serviceType) {
case USER:
result = new UserService.Client(protocol);
break;
case MESSAGE:
result = new MessageService.Client(protocol);
break;
}
return (T)result;
}