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.

28 lines
876 B

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();
}
}