View on GitHub

ScaleCube Reactive Microservices

The Future is reactive - The Future is right here!

Provisioning Clustered Services

So far we have learned how to define and implement a service, actually it was nothing more then implementing a java component. at this section we will learn how to provision our components as clustered micro services.

  // Create microservice provider
  Microservices provider = Microservices.builder()
    .port(4002) // base port
    .services(new GreetingServiceImpl(),...)

The line above introduces the service component to the cluster .port(4002), it reads the information from the service interface. and registers the instance in the cluster using the .services(...) option. its possible to introduce many service instances to the cluster or clusters for example by running several jvm instances each containing a service instance or having many services in the same JVM instance.

.port(4002) port is the base port the Microservices member to listen on, by default it might increment +n if the base port is taken. once a port is allocated the requested services will register the service on the newly allocated port. if not specified the default base port is 4000.

Service Tags

It is also possible to register services with service tags. the service .tag(key,value) is a user defined property as that describes a service instance. tag helps to distinguish instances and a single instance my ..add() several tags.
Possible reasons for Tags:
- we wish route an select a specific service instance 30% of the times.
- give specific instance some special role in the cluster.
- always choose the most latest version of a service.
- ...

 Microservices provider = Microservices.builder()
    .services().service(new GreetingServiceImpl())
            .tag("Weight", "0.3").add()
            .tag("Version", "1.0.3").add()
            .tag("Role", "Master").add()