Skip to content
This repository has been archived by the owner on May 11, 2021. It is now read-only.

Service discovery

skoky76 edited this page Jun 22, 2015 · 12 revisions

Description

This project reuses the beans and configurations set up in the micro-deps-spring-config project. Please check the documentation of that project to receive more in depth information about its content.

To put it briefly we are setting up via @EnableServiceDiscovery. This annotation imports ServiceDiscoveryConfiguration that imports ServiceResolverConfiguration configurations and beans that provide (names in brackets are names of classes)

  • Microservice's host and port (MicroserviceAddressProvider)
  • Zookeeper connection client (CuratorFramework)
  • Registration of the microservice in Zookeeper (ServiceInstance)
  • Service discovery (ServiceDiscovery)
  • Dependency watching - checking if dependency is still alive (DependencyWatcher)
  • Parsing of microservice configuration - defaults to classpath resource microservice.json (ServiceConfigurationResolver)
  • Service resolution (ServiceResolver)

Read more about dependencies configuration and Spring configuration.

Module configuration

If you want to use only this module just add a dependency:

repositories {
    jcenter()
}

dependencies {
    compile 'com.ofg:micro-infra-spring-base:0.6.0'
}

and the you have to enable service discovery via annotation:

@Configuration
@EnableServiceDiscovery
class MyWebAppConfiguration {
}

Runtime inspection

Every microservice exposes endpoints showing currently running services and their connectivity.

/collaborators

/collaborators returns all addresses of all instances of my collaborators:

curl -qs localhost:8095/collaborators | python -mjson.tool
{
    "com/ofg/twitter-places-collerator": {
        "http://127.0.1.1:8096": "DOWN",
        "http://127.0.1.1:8097": "UP"
    }
}

/collaborators/all

/collaborators/all endpoint aggregates /collaborator responses from all instances of all microservices in the system:

curl -qs localhost:8095/collaborators/all | python -mjson.tool
{
    "com/ofg/twitter-places-analyzer": {
        "http://127.0.1.1:8095": {
            "collaborators": {
                "com/ofg/twitter-places-collerator": {
                    "http://127.0.1.1:8096": "DOWN",
                    "http://127.0.1.1:8097": "UP"
                }
            },
            "status": "UP"
        }
    },
    "com/ofg/twitter-places-collerator": {
        "http://127.0.1.1:8096": {
            "collaborators": {},
            "status": "DOWN"
        },
        "http://127.0.1.1:8097": {
            "collaborators": {},
            "status": "UP"
        }
    },
    "com/ofg/social-engine": {
        "http://127.0.1.1:8098": {
            "collaborators": {
                "com/ofg/twitter-places-analyzer": {
                    "http://127.0.1.1:8095": "UP"
                }
            },
            "status": "UP"
        }
    }
}

/collaborators/view.html

/collaborators/view.html is a simple JavaScript view of data returned from collaborators/all:

Red arrow means that connectivity between given two services is broken. Red circle represents unresponsive service (even /ping doesn't respond). Notice that it's possible to have working (green) microservice but some connections to it broken. The opposite would be quite unusual.