You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
996 B
32 lines
996 B
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 {
|
|
// 实现抽象类的具体子类
|
|
}
|
|
}
|