You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/08/21 12:55:37 UTC
[GitHub] [dubbo] deliangc opened a new issue, #10489: 如何使用接口 ServiceDiscovery 获取某个服务名下的所有实例?
deliangc opened a new issue, #10489:
URL: https://github.com/apache/dubbo/issues/10489
1. 接口:org.apache.dubbo.registry.client.ServiceDiscovery#getInstances(java.lang.String)
2. 期待的使用方式
```java
public class A {
@Autowired
private ServiceDiscovery serviceDiscovery;
public void m1(){
serviceDiscovery.getInstances("serviceName")
}
}
```
3. 如果得到 ServiceDiscovery 实例呢?
4. 测试中使用的 zookeeper
file=org.apache.dubbo.registry.client.FileSystemServiceDiscovery
multicast=org.apache.dubbo.registry.multicast.MulticastServiceDiscovery
**zookeeper=org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery**
nacos=org.apache.dubbo.registry.nacos.NacosServiceDiscovery
multiple=org.apache.dubbo.registry.multiple.MultipleServiceDiscovery
kubernetes=org.apache.dubbo.registry.kubernetes.KubernetesServiceDiscovery
dns=org.apache.dubbo.registry.dns.DNSServiceDiscovery
xds=org.apache.dubbo.registry.xds.XdsServiceDiscovery
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] jiangyunshu commented on issue #10489: 如何使用接口 ServiceDiscovery 获取某个服务名下的所有实例?
Posted by GitBox <gi...@apache.org>.
jiangyunshu commented on issue #10489:
URL: https://github.com/apache/dubbo/issues/10489#issuecomment-1222006387
如果非要使用ServiceDiscovery。可以根据不同的协议,构造不同的ServiceDiscovery实例。例如nacos协议,
ServiceDiscovery serviceDiscovery= new NacosServiceDiscovery( ApplicationModel.defaultModel(),URL.valueOf("nacos://127.0.0.1:8848"));
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] AlbumenJ commented on issue #10489: 如何使用接口 ServiceDiscovery 获取某个服务名下的所有实例?
Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on issue #10489:
URL: https://github.com/apache/dubbo/issues/10489#issuecomment-1222003540
ServiceDiscovery这个对象是给 Dubbo 内部使用的,为什么要从这里获取实例信息呢
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] deliangc commented on issue #10489: 如何获取某个服务名下的所有实例?
Posted by GitBox <gi...@apache.org>.
deliangc commented on issue #10489:
URL: https://github.com/apache/dubbo/issues/10489#issuecomment-1229984225
问题没有得到解决,还是关了吧!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] AlbumenJ commented on issue #10489: 如何获取某个服务名下的所有实例?
Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on issue #10489:
URL: https://github.com/apache/dubbo/issues/10489#issuecomment-1226884325
ServiceDiscovery 有 ServiceInstanceChangedListstener 可以监听变更
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] AlbumenJ commented on issue #10489: 如何获取某个服务名下的所有实例?
Posted by GitBox <gi...@apache.org>.
AlbumenJ commented on issue #10489:
URL: https://github.com/apache/dubbo/issues/10489#issuecomment-1223423658
`org.apache.dubbo.registry.support.RegistryManager` 这个对象存储了所有的注册中心
org.apache.dubbo.registry.support.RegistryManager.getInstance(ApplicationModel.defaultModel()) 可以获取
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] deliangc commented on issue #10489: 如何获取某个服务名下的所有实例?
Posted by GitBox <gi...@apache.org>.
deliangc commented on issue #10489:
URL: https://github.com/apache/dubbo/issues/10489#issuecomment-1222193163
> ServiceDiscovery这个对象是给 Dubbo 内部使用的,为什么要从这里获取实例信息呢
事实上我的需求是:如何获取某个服务名下的所有实例?
已经修改了 issue title
如果能够获取到某个服务名下的所有实例,任何方式都可以。感谢!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] deliangc commented on issue #10489: 如何获取某个服务名下的所有实例?
Posted by GitBox <gi...@apache.org>.
deliangc commented on issue #10489:
URL: https://github.com/apache/dubbo/issues/10489#issuecomment-1223710885
> `org.apache.dubbo.registry.support.RegistryManager` 这个对象存储了所有的注册中心
>
> org.apache.dubbo.registry.support.RegistryManager.getInstance(ApplicationModel.defaultModel()) 可以获取
## 测试
- 使用的 zookeeper 作为注册中心
- 使用 dubbo 泛化调用
- dubbo 版本 3.0.4
### 1. 构建 Bean
```java
import org.apache.dubbo.registry.support.RegistryManager;
@Bean
public RegistryManager registryManager() {
return ApplicationModel.defaultModel().getBeanFactory().getBean(RegistryManager.class);
}
```
### 2. 使用 Bean
```java
import org.apache.dubbo.registry.Registry;
import org.apache.dubbo.registry.client.ServiceDiscoveryRegistry;
import org.apache.dubbo.registry.client.ServiceInstance;
import org.apache.dubbo.registry.support.RegistryManager;
import org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery;
@RestController
public class ServiceDiscoveryController {
private String key = "service-discovery-registry://192.168.2.228:2181/infra-dubbo/org.apache.dubbo.registry.RegistryService";
@Autowired
private RegistryManager registryManager;
/**
* curl http://localhost:8082/getInstances
*/
@GetMapping("/getInstances")
public Set<String> getInstances() {
Registry registry = registryManager.getRegistry(key);
ServiceDiscoveryRegistry serviceDiscoveryRegistry = (ServiceDiscoveryRegistry)registry;
ZookeeperServiceDiscovery serviceDiscovery = (ZookeeperServiceDiscovery)serviceDiscoveryRegistry.getServiceDiscovery();
Set<String> services = serviceDiscovery.getServices();
List<ServiceInstance> instances = serviceDiscovery.getInstances("A.dubbo.service");
return services;
}
}
```
### 测试问题列表
1. 默认使用的 basePath 为 `services` :org.apache.curator.x.discovery.details.ServiceDiscoveryImpl#pathForName 。而我实际使用的 basePath 为 `infra-dubbo`
2. 当然可以通过在 url 添加参数 `rootPath` 来修改 basePath :org.apache.dubbo.registry.zookeeper.ZookeeperServiceDiscovery#doInitialize
```java
@Override
public void doInitialize(URL registryURL) throws Exception {
this.registryURL = registryURL;
this.curatorFramework = buildCuratorFramework(registryURL);
this.rootPath = ROOT_PATH.getParameterValue(registryURL);
this.serviceDiscovery = buildServiceDiscovery(curatorFramework, rootPath);
this.serviceDiscovery.start();
}
```
3. 在 paramers 上添加了 rootPath KV对,但是 `registryURL` 上添加不了 rootPath 参数,导致无法修改默认值`services`
4. 即便是第2步能够满足,这个也是每次通过 `org.apache.curator.x.discovery.ServiceDiscovery<ZookeeperInstance> serviceDiscovery;` 去 zk 注册中心获取的,而没有缓存到本地,也是不可取的。
### 问题:当 A 服务名调用 B 服务名,假设 B 服务名的实例集合为S,A的某个实例本地一定缓存得有集合S,并且A实例本地会监听 B 实例的变化并对集合S进行`增删改`,那么 A实例能不能得到B的实例集合 S 呢?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
[GitHub] [dubbo] deliangc closed issue #10489: 如何获取某个服务名下的所有实例?
Posted by GitBox <gi...@apache.org>.
deliangc closed issue #10489: 如何获取某个服务名下的所有实例?
URL: https://github.com/apache/dubbo/issues/10489
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org