ScaleCube is a microservices library designed for high throughput and lower latency, catering to scalable and reactive system needs. It excels in API gateway integration, service discovery, and load balancing, employing the SWIM protocol for efficient cluster management. Its modular architecture supports various pluggable communication modules, enabling seamless and flexible deployments. With a focus on real-time stream processing and fault tolerance, ScaleCube ensures optimal performance and reliability for distributed microservices environments.
Reactive microservices communicate via streams, utilising asynchronous data flows to exchange information between services. This approach enhances system responsiveness and scalability by allowing services to process and react to data as it arrives, without blocking operations.
In practice, this involves using technologies and protocols that support reactive streams, such as Reactor. These tools enable the development of highly responsive, resilient systems capable of handling dynamic workloads efficiently.
A fully mesh, brokerless architecture is particularly beneficial for high-performing, reliable, and scalable applications.
It ensures continuous availability and responsiveness, making it ideal for real-time data processing, large-scale distributed systems, and environments where minimizing latency matters. ScaleCube’s fully mesh architecture delivers a robust, efficient, and scalable solution for modern microservices applications, enhancing system performance and reliability without the need for complex middleware setups. |
ScaleCube Services Features:
User Guide:
Basic Usage:
The example provisions 2 cluster nodes and making a remote interaction.
// service definition
@Service("io.scalecube.Greetings")
public interface GreetingsService {
@ServiceMethod("sayHello")
Mono<Greeting> sayHello(String name);
}
}
// service implementation
public class GreetingServiceImpl implements GreetingsService {
@Override
public Mono<Greeting> sayHello(String name) {
return Mono.just(new Greeting("Nice to meet you " + name + " and welcome to ScaleCube"));
}
}
//1. ScaleCube Node node with no members (container 1)
Microservices seed = Microservices.builder()
.discovery("seed", ScalecubeServiceDiscovery::new)
.transport(RSocketServiceTransport::new)
.startAwait();
// get the address of the seed member - will be used to join any other members to the cluster.
final Address seedAddress = seed.discovery("seed").address();
//2. Construct a ScaleCube node which joins the cluster hosting the Greeting Service (container 2)
Microservices serviceNode = Microservices.builder()
.discovery("seed", ep -> new ScalecubeServiceDiscovery(ep)
.membership(cfg -> cfg.seedMembers(seedAddress)))
.transport(RSocketServiceTransport::new)
.services(new GreetingServiceImpl())
.startAwait();
//3. Create service proxy (can be created from any node or container in the cluster)
// and Execute the service and subscribe to incoming service events
seed.call().api(GreetingsService.class)
.sayHello("joe").subscribe(consumer -> {
System.out.println(consumer.message());
});
// await all instances to shutdown.
Mono.whenDelayError(seed.shutdown(), serviceNode.shutdown()).block();
Basic Service Example:
A service is nothing but an interface declaring what methods we wish to provision at our cluster.
@Service
public interface ExampleService {
@ServiceMethod
Mono<String> sayHello(String request);
@ServiceMethod
Flux<MyResponse> helloStream();
@ServiceMethod
Flux<MyResponse> helloBidirectional(Flux<MyRequest> requests);
}
Available api-gateways are rsocket, http and websocket
Basic API-Gateway example:
Microservices.builder()
.discovery(options -> options.seeds(seed.discoveryAddress()))
.services(...) // OPTIONAL: services (if any) as part of this node.
// configure list of gateways plugins exposing the apis
.gateway(options -> new WebsocketGateway(options.id("ws").port(8080)))
.gateway(options -> new HttpGateway(options.id("http").port(7070)))
.gateway(options -> new RSocketGateway(options.id("rsws").port(9090)))
.startAwait();
// HINT: you can try connect using the api sandbox to these ports to try the api.
// https://scalecube.github.io/api-sandbox/app/index.html
With scalecube-services you may plug-and-play alternative providers for Transport,Codecs and discovery. Scalecube is using ServiceLoader to load providers from class path,
You can think about scalecube as slf4j for microservices - Currently supported SPIs:
Transport providers:
Message codec providers:
Service discovery providers:
Binaries and dependency information for Maven can be found at http://search.maven.org.
https://mvnrepository.com/artifact/io.scalecube
To add a dependency on ScaleCube Services using Maven, use the following:
<properties>
<scalecube.version>2.x.x</scalecube.version>
</properties>
<!-- -------------------------------------------
scalecube core and api:
------------------------------------------- -->
<!-- scalecube apis -->
<dependency>
<groupId>io.scalecube</groupId>
<artifactId>scalecube-services-api</artifactId>
<version>${scalecube.version}</version>
</dependency>
<!-- scalecube services module -->
<dependency>
<groupId>io.scalecube</groupId>
<artifactId>scalecube-services</artifactId>
<version>${scalecube.version}</version>
</dependency>
<!--
Plugins / SPIs: bellow a list of providers you may choose from. to constract your own configuration:
you are welcome to build/contribute your own plugins please consider the existing ones as example.
-->
<!-- scalecube transport providers: -->
<dependency>
<groupId>io.scalecube</groupId>
<artifactId>scalecube-services-transport-rsocket</artifactId>
<version>${scalecube.version}</version>
</dependency>