parent
935fac1941
commit
fe22a33ba6
@ -0,0 +1,31 @@
|
||||
package mxdx1;
|
||||
|
||||
public class ServiceClientTest {
|
||||
public static void main(String[] args) {
|
||||
// 创建服务
|
||||
UserService userService1 = new UserService("localhost", 8081);
|
||||
UserService userService2 = new UserService("localhost", 8082);
|
||||
|
||||
// 创建客户端实现类
|
||||
MyServiceClient client = new MyServiceClient();
|
||||
client.subscribe("user-service");
|
||||
|
||||
// 启动服务
|
||||
userService1.start();
|
||||
userService2.start();
|
||||
|
||||
// 测试服务调用
|
||||
System.out.println(client.invoke("user-service", "getUserInfo", "1001"));
|
||||
|
||||
// 停止一个用户服务
|
||||
userService1.stop();
|
||||
|
||||
// 再次调用,验证服务发现是否更新
|
||||
System.out.println(client.invoke("user-service", "getUserInfo", "1001"));
|
||||
}
|
||||
|
||||
// ServiceClient 的具体实现类
|
||||
static class MyServiceClient extends ServiceClient {
|
||||
// 实现抽象类的具体子类
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue