Introduction | Core Concept | Mechanics | Components | Getting Started | Build Nano | Benefits
Back to basics and forget about frameworks!
Nano is a lightweight concept which makes it easier for developer to write microservices in functional, fluent, chaining, plain, modern java with a nano footprint. Nano is also designed to be fully compilable with GraalVM to create native executables. To enhance efficiency and performance, Nano utilizes non-blocking virtual threads from Project Loom.
Nano handles threads for you and provides a basic construct for event driven architecture. It's providing a simple way to write microservices in a functional fluent and chaining style. Objects are less needed thanks to the underlying TypeMap. Nano provides full access to all internal components, resulting in very few private methods or fields.
All you need to know are few classes: Context, Events, Logger, Schedulers, Services
flowchart LR
nano(((Nano))) --> context[Context]
context --> logger[Logger]
logger --> events[Events]
events --> services[Services]
services --> schedulers[Schedulers]
style nano fill:#90CAF9,stroke:#1565C0,stroke-width:1px,color:#1A237E,rx:2%,ry:2%
style context fill:#90CAF9,stroke:#1565C0,stroke-width:1px,color:#1A237E,rx:2%,ry:2%
style logger fill:#90CAF9,stroke:#1565C0,stroke-width:1px,color:#1A237E,rx:2%,ry:2%
style events fill:#90CAF9,stroke:#1565C0,stroke-width:1px,color:#1A237E,rx:2%,ry:2%
style services fill:#90CAF9,stroke:#1565C0,stroke-width:1px,color:#1A237E,rx:2%,ry:2%
style schedulers fill:#90CAF9,stroke:#1565C0,stroke-width:1px,color:#1A237E,rx:2%,ry:2%
Maven example
<dependency>
<groupId>berlin.yuna</groupId>
<artifactId>nano</artifactId>
<version>1.0.0</version>
</dependency>
Gradle example
dependencies {
implementation 'berlin.yuna:nano:1.0.0'
}
Simple Nano example with HttpService (a default service)
public static void main(final String[] args) {
// Start Nano with HttpService
final Nano app = new Nano(args, new HttpService());
// listen to /hello
app.subscribeEvent(EVENT_HTTP_REQUEST, event -> event.payloadOpt(HttpObject.class)
.filter(HttpObject::isMethodGet)
.filter(request -> request.pathMatch("/hello"))
.ifPresent(request -> request.response().body(Map.of("Hello", System.getProperty("user.name"))).respond(event)));
// Override error handling for HTTP requests
app.subscribeEvent(EVENT_APP_UNHANDLED, event -> event.payloadOpt(HttpObject.class).ifPresent(request ->
request.response().body("Internal Server Error [" + event.error().getMessage() + "]").statusCode(500).respond(event)));
}
add the native-image profile to your pom.xml
and run mvn package -Pnative-image
<profiles>
<!-- NATIVE COMPILATION -->
<plugin>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>native-image-maven-plugin</artifactId>
<version>21.2.0</version>
<configuration>
<imageName>ExampleApp</imageName>
<mainClass>de.yuna.berlin.nativeapp.helper.ExampleApp</mainClass>
<buildArgs>
<!-- Reduces the image size - Ensures the native image doesn't include the JVM as a fallback option -->
<buildArg>--no-fallback</buildArg>
<!-- Disables the use of the GraalVM compilation server -->
<buildArg>--no-server</buildArg>
<!-- Improve startup time - Initialize classes at build time rather than at runtime -->
<buildArg>--initialize-at-build-time</buildArg>
<!-- Include all files under /resources -->
<buildArg>-H:IncludeResources=resources/config/.*</buildArg>
</buildArgs>
</configuration>
<executions>
<execution>
<goals>
<goal>native-image</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
</profiles>
Contributions to Nano are welcome! Please refer to our Contribution Guidelines for more information.
Nano is open-source software licensed under the Apache license.
If you encounter any issues or have questions, please file an issue here.