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 than implementing a Java component.
In this section we will learn how to provision our components as clustered Microservices .

  // Create microservice provider
  Microservices provider = Microservices.builder()
    .discovery(options -> options.seeds(....))
    .services(new GreetingServiceImpl(),...)
    .startAwait();

The line above introduces the service component to the cluster, it reads the information from the service interface and registers the instance in the cluster using the .services(...) option. It iss 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.

Service Tags

It is also possible to register services with service tags. The service .tag(key,value) is a user defined property used to describe a service instance. Tag helps to distinguish instances and a single instance, it is possible to add several tags to the service description.
Following are several examples use-cases of Service Tags:
- Route and select a specific service instance 30% of the times.
- Assign a specific service instance with special role in the cluster.
- Always choose the latest version of a service.
- ...

    Microservices services1 = Microservices.builder()
        .discovery(options -> options.seeds(....))
        .service(ServiceInfo.fromServiceInstance(new GreetingServiceImpl())
              .tag("Weight", "0.3")
              .tag("Version", "1.0.3")
              .tag("Role", "Master")
            .build())
        .startAwait();