
io.scalecube.services.Microservices Maven / Gradle / Ivy
package io.scalecube.services;
import static java.util.Objects.requireNonNull;
import io.scalecube.cluster.Cluster;
import io.scalecube.cluster.ClusterConfig;
import io.scalecube.services.ServiceCall.Call;
import io.scalecube.services.discovery.ServiceDiscovery;
import io.scalecube.services.discovery.ServiceScanner;
import io.scalecube.services.metrics.Metrics;
import io.scalecube.services.registry.ServiceRegistryImpl;
import io.scalecube.services.registry.api.ServiceRegistry;
import io.scalecube.services.routing.RoundRobinServiceRouter;
import io.scalecube.services.routing.Router;
import io.scalecube.services.routing.RouterFactory;
import io.scalecube.services.transport.DefaultServiceMessageAcceptor;
import io.scalecube.services.transport.LocalServiceDispatchers;
import io.scalecube.services.transport.ServiceTransport;
import io.scalecube.services.transport.client.api.ClientTransport;
import io.scalecube.services.transport.server.api.ServerTransport;
import io.scalecube.transport.Address;
import io.scalecube.transport.Addressing;
import com.codahale.metrics.MetricRegistry;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import reactor.core.publisher.Mono;
/**
* The ScaleCube-Services module enables to provision and consuming microservices in a cluster. ScaleCube-Services
* provides Reactive application development platform for building distributed applications Using microservices and fast
* data on a message-driven runtime that scales transparently on multi-core, multi-process and/or multi-machines Most
* microservices frameworks focus on making it easy to build individual microservices. ScaleCube allows developers to
* run a whole system of microservices from a single command. removing most of the boilerplate code, ScaleCube-Services
* focuses development on the essence of the service and makes it easy to create explicit and typed protocols that
* compose. True isolation is achieved through shared-nothing design. This means the services in ScaleCube are
* autonomous, loosely coupled and mobile (location transparent)—necessary requirements for resilance and elasticity
* ScaleCube services requires developers only to two simple Annotations declaring a Service but not regards how you
* build the service component itself. the Service component is simply java class that implements the service Interface
* and ScaleCube take care for the rest of the magic. it derived and influenced by Actor model and reactive and
* streaming patters but does not force application developers to it. ScaleCube-Services is not yet-anther RPC system in
* the sense its is cluster aware to provide:
*
* - location transparency and discovery of service instances.
* - fault tolerance using gossip and failure detection.
* - share nothing - fully distributed and decentralized architecture.
* - Provides fluent, java 8 lambda apis.
* - Embeddable and lightweight.
* - utilizes completable futures but primitives and messages can be used as well completable futures gives the
* advantage of composing and chaining service calls and service results.
* - low latency
* - supports routing extensible strategies when selecting service end-points
*
*
* basic usage example:
*
*
* {@code
* // Define a service interface and implement it:
* @ Service
* public interface GreetingService {
* @ ServiceMethod
* Mono asyncGreeting(String string);
* }
*
* public class GreetingServiceImpl implements GreetingService {
* @ Override
* public Mono asyncGreeting(String name) {
* return CompletableFuture.completedFuture(" hello to: " + name);
* }
* }
*
* // Build a microservices cluster instance:
* Microservices microservices = Microservices.builder()
* // Introduce GreetingServiceImpl pojo as a micro-service:
* .services(new GreetingServiceImpl())
* .build();
*
* // Create microservice proxy to GreetingService.class interface:
* GreetingService service = microservices.call()
* .api(GreetingService.class);
*
* // Invoke the greeting service async:
* Mono future = service.sayHello("joe");
*
* // handle completable success or error:
* future.whenComplete((result, ex) -> {
* if (ex == null) {
* // print the greeting:
* System.out.println(result);
* } else {
* // print the greeting:
* System.out.println(ex);
* }
* });
* }
*
*/
public class Microservices {
public static final int SERVICE_PORT = 5801;
private final ServiceRegistry serviceRegistry;
private final ClientTransport client;
private final Metrics metrics;
private final Address serviceAddress;
public final RouterFactory routerFactory;
private final ServiceDiscovery discovery;
private final ServerTransport server;
private final LocalServiceDispatchers serviceDispatchers;
private final List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy