Reputation: 455
I built two different service connector for one service. If I add both service connector to my application Spring will not start saying there is no suitable service connector found. I debugged into spring and found only one of the connectors being added to the internal connector list. Is it possible to add two different spring cloud service connectors for one service and use them within one application?
For a better understanding an example with a rabbitMQ service. Let's say I've build two different Cloud Service Connectors with a CloudFoundryServiceInfoCreator<AMQConnectionInfo>
and a CloudFoundryServiceInfoCreator<MQTTConnectionInfo>
. I would like to use both connectors in the application (I know I could implement both connection info in one spring cloud connector, but that's not what I would like to do).
edit: The following exception is raised:
org.springframework.cloud.CloudException: No unique service matching class .... found. Expected 1, found 0
at org.springframework.cloud.Cloud.getSingletonServiceConnector(Cloud.java:149)
I also tried to use cloud.getServiceConnector(id, class, null);
.
I also just found that Spring Cloud Connectors just returns the first Connector which is found within this method in 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;
}
I think it would be nice if this would return a list of suitable ServiceInfoCreator or searches for the one I requested, wouldn't it?
Upvotes: 0
Views: 305