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

楼主解决了吗 一样的问题

0
0

刘果国

2018-12-05

留个联系方式,远程看一下吧

0
1
邱吹神
我遇到同样的问题。18682408814,我联系方式。希望能加老师微信
2019-09-13
共1条回复

Docker+Kubernetes(k8s)微服务容器化实践

从开发到编排,快速,完整,深入的掌握微服务

2607 学习 · 607 问题

查看课程