Skip to content

v0.87 of Microserver : Stream across services, Standardized error handling

Compare
Choose a tag to compare
@johnmcclean johnmcclean released this 07 Jul 16:25
· 376 commits to master since this release

New in Microserver v0.87

  • Use Java 8 Streams (or reactive-streams Publishers) to Stream data between Microservices.
  • Standardized error codes, error handling and health checks
  • Decisioning for micro-async-data-writer and loader tasks (e.g. have only an elected leader execute)
  • DistributedMap abstraction (backed by S3 or Couchbase)

Streaming across Services with micro-reactive

@GET
@Produces("application/json")
@Path("/infinite-boo")
public Response boo() {
       return ReactiveResponse.publishAsJson(ReactiveSeq.generate(() -> "boo!"));

}
@GET
@Produces("application/json")
@Path("/infinite-boo-jdk")
public Response booJDK() {
       return ReactiveResponse.streamAsJson(Stream.generate(() -> "boo!"));

}

To Stream in output from our infinetely Streaming Rest end points we can write

new ReactiveRequest(1000, 1000).getJsonStream("http://localhost:8080/simple-app/single/infinite-boo",String.class)
                               .forEach(System.err::println);

Standardized error handling with micro-error-codes

Features

  1. ErrorCode class for defining error codes
  2. ErrorBus and abstract BaseException type that accepts ErrorCode and posts errors through the ErrorBus
  3. HealthCheck service that tracks error state of an application (e.g. Ok, Errors, Fatal)
  4. Configurable Rest end point for viewing status & errors

Define errors - FATAL denotes an unrecoverable failure

public interface Errors {
    public final static ErrorCode QUERY_FAILURE = ErrorCode.error(1, "User {0} missing", Severity.CRITICAL);
    public final static ErrorCode SYSTEM_FAILURE = ErrorCode.error(2, "data {0} mismatch, corruption likely", Severity.FATAL);
}

Throwing an Exception will ensure the error is tracked via an Error EventBus, and health check status will be updated.

try{

}catch(Exception e){
        throw new InvalidStateException(Errors.SYSTEM_FAILURE.format(systemRecord),e);
}

Dependency upgrades

None this time

What is Microserver?

Microserver is a plugin engine for building Spring and Spring Boot based microservices. Microserver supports pure microservice and micro-monolith development styles. The micro-monolith style involves packaging multiple services into a single deployment - offering developers the productivity of microservice development without the operational risk. This can help teams adopt a Microservices architecture on projects that are currently monoliths.

Microserver plugins are orthogonal to Microservices. They solve a common problem in Microservice development where by services are broken up and deployed separately but code remains entangled in a monolithic common library. By making use of a plugin system that follows the same modular archictectural principals as microservice development, teams can keep cross-service concerns and infrastructure in properly size, coherent and cohesive plugin modules.

Checkout the available plugins here : each plugin has it's own readme.md

screen shot 2016-05-06 at 12 30 26 pm

Getting Microserver

Maven dependency

Microserver for Spring Boot

    <dependency>
      <groupId>com.aol.microservices</groupId>
      <artifactId>micro-spring-boot</artifactId>
      <version>0.87</version>
    </dependency>

Microserver Grizzly with Jersey

    <dependency>
      <groupId>com.aol.microservices</groupId>
      <artifactId>micro-grizzly-with-jersey</artifactId>
      <version>0.87</version>
    </dependency>

Microserver Tomcat with Jersey

    <dependency>
      <groupId>com.aol.microservices</groupId>
      <artifactId>micro-tomcat-with-jersey</artifactId>
      <version>0.87</version>
    </dependency>

Other modules are available in Maven Central

Gradle dependency

Microserver Spring Boot

      compile group: 'com.aol.microservices', name:'micro-spring-boot', version:'0.87'

Microserver grizzly-with-jersey

     compile group: 'com.aol.microservices', name:'micro-grizzly-with-jersey', version:'0.87'

Microserver tomcat-with-jersey

     compile group: 'com.aol.microservices', name:'micro-tomcat-with-jersey', version:'0.87'

Java Doc : Microserver Core
Java Doc : Microserver Spring Boot - full stack
Java Doc : Microserver Boot - backends
Java Doc : Microserver Jdbc
Java Doc : Microserver HikariCP
Java Doc : Microserver dbcp
Java Doc : Microserver Hibernate
Java Doc : Microserver Grizzly
Java Doc : Microserver Tomcat
Java Doc : Microserver Jersey
Java Doc : Microserver Swagger
Java Doc : Microserver Metrics
Java Doc : Microserver Reactive
Java Doc : Microserver Events
Java Doc : Microserver MySQL
Java Doc : Microserver Couchbase
Java Doc : Microserver Ip Tracker
Java Doc : Microserver Application Register
Java Doc : Microserver Machine Stats
Java Doc : Microserver Cors
Java Doc : Microserver Client
Java Doc : Microserver Jackson Configuration
Java Doc : Microserver General Exception Mapper
Java Doc : Microserver Transactions
Java Doc : Microserver Curator
Java Doc : Microserver S3
Java Doc : Microserver Javaslang
Java Doc : Microserver Log4j
Java Doc : Microserver Logback
Java Doc : Microserver Manifest Comparator
Java Doc : Microserver Async Data Writer
Java Doc : Microserver Async Data Loader
Java Doc : Microserver Dist Lock
Java Doc : Microserver Error Codes
Java Doc : Microserver Logback