thrift 客户端连接服务端问题
来源:3-7 开发用户EdgeService_B
Jakarta开发者
2018-12-04
刘老师,thrift服务端启动后,客户端连接报异常了,研究了半天没有看懂,代码上我也仔细检查了,没有错,端口,也查看了,都正常启动的,有些时候这个位置抛空指针异常,
org.apache.thrift.transport.TTransportException: java.net.ConnectException: 拒绝连接 (Connection refused), 抛拒绝连接
thrift服务端 没有打印任何信息
这是thrift客户端的配置:
@Log4j
@Component
public class ServiceProvider {
@Value("${thrift.user.ip}")
private String serverIp;
@Value("${thrift.user.port}")
private int serverPort;
@Value("${thrift.message.ip}")
private String messageServerIp;
@Value("${thrift.message.port}")
private int messageServerPort;
private enum ServiceType {
USER,
MESSAGE
}
public UserService.Client getUserService() {
return getService(serverIp, serverPort, ServiceType.USER);
}
public MessageService.Client getMessasgeService() {
return getService(messageServerIp, messageServerPort, ServiceType.MESSAGE);
}
public <T> 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;
default:
break;
}
return (T) result;
}
}
这是thrift服务端的配置:
@Log4j
@Configuration
public class ThriftServer {
@Value("${service.port}")
private int servicePort;
private final UserService.Iface userService;
@Autowired
public ThriftServer(UserService.Iface userService) {
this.userService = userService;
}
@PostConstruct
public void startThriftServer() {
log.info("服务端开启....");
TProcessor processor = new UserService.Processor<>(userService);
TNonblockingServerSocket socket = null;
try {
socket = new TNonblockingServerSocket(servicePort);
} catch (TTransportException e) {
e.printStackTrace();
}
TNonblockingServer.Args args = new TNonblockingServer.Args(socket);
args.processor(processor);
args.transportFactory(new TFramedTransport.Factory());
args.protocolFactory(new TBinaryProtocol.Factory());
TServer server = new TNonblockingServer(args);
server.serve();
}
}
这是thrift客户端配置
研究了半天没有看出来哪里出问题了,希望刘老师指导一下,谢谢!
写回答
2回答
-
慕莱坞7666040
2019-01-21
楼主解决了吗 一样的问题
00 -
刘果国
2018-12-05
留个联系方式,远程看一下吧
012019-09-13
相似问题
课程3-7:如何判断数据库正常连接
回答 1
服务间调用问题
回答 2