spring-cloud-connectors icon indicating copy to clipboard operation
spring-cloud-connectors copied to clipboard

Multiple ServiceConnectorCreators for one Service

Open mortenri opened this issue 6 years ago • 0 comments

Hi,

I found the issue: https://github.com/spring-cloud/spring-cloud-connectors/issues/121 but I'm not able to comment or reopen it. I guess I'm just missing something (I'm new to this).

I implemented two different CloudServiceConnectors for one service. I found the solution provided in issue#121 which not really suits the needs for my use-case. In my case, I would like to make the service connectors pluggable to avoid dependencies the user might not want. If I would use a BaseCompositeServiceInfo I would either always create two different ServiceInfos or create a ServiceInfo if it is present in the classpath to avoid forcing the user to get some dependencies.

In the Class org.springframework.cloud.AbstractCloudConnector I found the following method which returns the first InfoCreator which is suitable.

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

This method could return a list of ÌnfoCreators or check if the object a user requested (cloud.getSingletonServiceConnector(SomeConnector.class, null) is suitable with one of the Infos instead of returning the first it finds, couldn't it?

Regards Morten

mortenri avatar Mar 07 '19 08:03 mortenri