DataEase

轻量级Java RPC框架

快速开始

安装Nacos作为注册中心

1. Spring

public interface HelloService {
    HelloDTO sayHello();
}
public class HelloDTO implements Serializable {
    private Integer id;
    private String name;

    public HelloDTO(Integer id, String name) {
        this.id = id;
        this.name = name;
    }

    @Override
    public String toString() {
        return "HelloDTO{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

服务提供方

@Service
@PhoenixService(interfaceClass = HelloService.class)
public class HelloServiceImpl implements HelloService {
    public HelloDTO sayHello() {
        return new HelloDTO(1, "abc");
    }
}
@Configuration
public class RpcConfig {
    @Bean
    public ServiceInitializer nettyServerAware() {
        return new ServiceInitializer("127.0.0.1", 9998, "127.0.0.1:8848");
    }
}

服务消费方

@RestController
public class HelloController {
    @PhoenixReference
    private HelloService helloService;

    @GetMapping("/hello")
    public HelloDTO sayHello() throws InterruptedException {
        return helloService.sayHello();
    }
}
@Configuration
public class RpcConfig {
    @Bean
    public ReferenceInitializer nettyServerAware() {
        return new ReferenceInitializer("127.0.0.1:8848");
    }
}

2. Spring Boot

// todo