In SOA/distributed systems, services need to find each other. i.e. a web service might need to find a caching service, etc. DNS can be used for this but it is nowhere near flexible enough for services that are constantly changing. A Service Discovery system provides a mechanism for:
In Soabase, Service Discovery is transparent for the most part. Soabase applications automatically register themselves and the REST Client Enhancements} use it to locate service instances. The default implementation uses Apache Curator. You only need to add configuration and the bundle.
Service Discovery is enabled via configuration. See the Service Discovery Configuration section for details. To use the default Apache Curator/ZooKeeper implementation, add CuratorConfiguration configuration to your application's Configuration object. If needed, you can access the SoaDiscovery instance from SoaFeatures.
A nice side-effect of using the standard Apache Curator integration is that you can directly access the CuratorFramework instance for any other ZooKeeper usage you might have. You can even create multiple CuratorFramework instances for different ZooKeeper clusters. Each Curator instance defined in your Configuration is set in SoaFeatures with the configured name.
To use something other than the Curator Service Discovery implementation, follow these steps:
SoaDiscoveryFactory
Your SoaDiscoveryFactory implementation is like other Dropwizard factories. It should be both configuration and a factory. Use ZooKeeperDiscoveryFactory.java as an example. This class must be annotated with JsonTypeName and given a unique name. You then use this name as the value for the attributes type in your configuration file. E.g.
package com.me.my; @JsonTypeName("my-discovery") public class MyDiscoveryFactory implements SoaDiscoveryFactory { public String aConfigValue; public int anotherConfigValue; ... @Override public SoaDiscovery build(Environment environment, SoaInfo soaInfo) { ... return new MyDiscovery(...); } }
SoaExtendedDiscovery
Your SoaDiscovery implementation does the actual work of Service Discovery. The details will depend on your implementation's needs. Note: your custom class should implement SoaExtendedDiscovery not SoaDiscovery. This allows your implementation to interact with the Administration Console.
ServiceLoader files
Like other Dropwizard plugins, your Service Discovery implementation needs Service Loader files. In the io.dropwizard.jackson.Discoverable file add a line containing: io.soabase.core.features.discovery.SoaDiscoveryFactory. In the io.soabase.core.features.discovery.SoaDiscoveryFactory file add a line the with fully-qualified path name of your class. E.g. com.me.my.MyDiscoveryFactory