parent
48767fa58d
commit
91c7ccb154
@ -0,0 +1,28 @@
|
||||
package mxdx1;
|
||||
|
||||
public class UserService {
|
||||
private ServiceInfo serviceInfo;
|
||||
private ServiceRegistry registry;
|
||||
|
||||
public UserService(String host, int port) {
|
||||
this.serviceInfo = new ServiceInfo("user-service", host, port);
|
||||
this.registry = ServiceRegistry.getInstance();
|
||||
}
|
||||
|
||||
// 启动服务并注册
|
||||
public void start() {
|
||||
System.out.println("User service started at " + serviceInfo.getHost() + ":" + serviceInfo.getPort());
|
||||
registry.register(serviceInfo);
|
||||
}
|
||||
|
||||
// 停止服务并注销
|
||||
public void stop() {
|
||||
System.out.println("User service stopped");
|
||||
registry.unregister(serviceInfo);
|
||||
}
|
||||
|
||||
// 业务方法
|
||||
public String getUserInfo(String userId) {
|
||||
return "User info for " + userId + " from " + serviceInfo.getHost() + ":" + serviceInfo.getPort();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue