spring - 一个服务的多个 Spring Cloud 服务连接器
问题描述
我为一项服务构建了两个不同的服务连接器。如果我将两个服务连接器都添加到我的应用程序中,Spring 将不会开始说没有找到合适的服务连接器。我调试到 spring 中,发现只有一个连接器被添加到内部连接器列表中。是否可以为一项服务添加两个不同的 spring 云服务连接器并在一个应用程序中使用它们?
为了更好地理解 rabbitMQ 服务的示例。假设我使用 aCloudFoundryServiceInfoCreator<AMQConnectionInfo>
和 a构建了两个不同的云服务连接器CloudFoundryServiceInfoCreator<MQTTConnectionInfo>
。我想在应用程序中使用这两个连接器(我知道我可以在一个弹簧云连接器中实现这两个连接信息,但这不是我想做的)。
编辑:引发以下异常:
org.springframework.cloud.CloudException: No unique service matching class .... found. Expected 1, found 0
at org.springframework.cloud.Cloud.getSingletonServiceConnector(Cloud.java:149)
我也尝试使用cloud.getServiceConnector(id, class, null);
.
我还发现 Spring Cloud Connectors 只返回在此方法中找到的第一个连接器org.springframework.cloud.AbstractCloudConnector
:
private ServiceInfo getServiceInfo(SD serviceData) {
for (ServiceInfoCreator<? extends ServiceInfo,SD> serviceInfoCreator : serviceInfoCreators) {
if (serviceInfoCreator.accept(serviceData)) {
return serviceInfoCreator.createServiceInfo(serviceData);
}
}
// Fallback with a warning
ServiceInfo fallackServiceInfo = getFallbackServiceInfoCreator().createServiceInfo(serviceData);
logger.warning("No suitable service info creator found for service " + fallackServiceInfo.getId()
+ " Did you forget to add a ServiceInfoCreator?");
return fallackServiceInfo;
}
我认为如果这会返回一个合适的 ServiceInfoCreator 列表或搜索我请求的列表会很好,不是吗?
解决方案
推荐阅读
- javascript - 电子从 ipcMain 发送数据到 ipcRender
- javascript - Javascript - 围绕异步 WebSocket 构建异步接口
- python - python-elasticsearch:如何启用 curl 日志记录?
- sql-server - 获取值不为空的第一个条目 SQL Server 2012
- elasticsearch - kibana 中的 ElasticSearch 内存使用情况与 Windows 不匹配
- javascript - 传入的对象无效,应为 ':' 或 '}'
- php - 包含的函数不能在 php 中包含的标头和导航栏文件中工作
- google-cloud-ml - 如何转换为多类分类模型?
- python - Python:PCM 音频操作 - 使用结构时左声道嘈杂
- ibm-mobilefirst - MobileFirst 7.1(错误:“访问服务器已禁用”)