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, Schedulers, Services
flowchart LR
nano(((Nano))) --> context[Context]
context --> 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 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%
- Error Handling
- Registers (ConfigRegister, TypeConversionRegister, LogFormatRegister, EventChannelRegister)
- Integrations (π± Spring Boot, π§βπ Micronaut, πΈ Quarkus)
- Code Examples
Maven example
<dependency>
<groupId>org.nanonative</groupId>
<artifactId>nano</artifactId>
<version>1.0.0</version>
</dependency>
Gradle example
dependencies {
implementation 'org.nanonative:nano:1.0.0'
}
Simple Nano example with HttpServer (a default service)
public static void main(final String[] args) {
// Start Nano with HttpServer
final Nano app = new Nano(args, new HttpServer());
// 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>
<!-- Impro
8000
ve 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>
- π§© Modular Design: Nano's architecture is modular, making it easy to understand, extend, and maintain.
- π§΅ Concurrency Management: Efficiently handle asynchronous tasks using advanced thread management.
- π‘ Event-Driven Architecture: Robust event handling that simplifies communication between different parts of your application.
- βοΈ Flexible Configuration: Configure your application using environment variables, system properties, or command-line arguments.
- π Robust Logging and Error Handling: Integrated logging and comprehensive error handling mechanisms for reliable operation.
- π Scalable and Performant: Designed with scalability and performance in mind to handle high-concurrency scenarios.
- πͺΆ Lightweight & Fast: Starts in milliseconds, uses ~10MB memory.
- πΏ Pure Java, Pure Simplicity: No reflections, no regex, no unnecessary magic.
- β‘ GraalVM Ready: For ahead-of-time compilation and faster startup.
- π Minimal Dependencies: Reduces CVE risks and simplifies updates.
- π Fluent & Stateless: Intuitive API design for easy readability and maintenance.
- π οΈ Rapid Service Development: Build real services in minutes.
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.