juneau-microservice
| Maven | |
|---|---|
| Jar | juneau-microservice-10.0.0.jar |
| OSGi | org.apache.juneau.microservice_10.0.0.jar |
| Links | Maven Central · Javadocs · Source |
Contents/Features
Juneau Microservice is an API for creating stand-alone executable jars with automatic support for Juneau configurations and console commands.
Features include:
- A builder-based API for defining and starting microservices.
- An extensible API that allows you to hook into various lifecycle events.
- Simple-to-use APIs for accessing manifest file entries, command-line arguments, and external configuration file properties.
- A bean-store-aware inject-style bootstrap (
@Configuration+@Bean) that lets companion modules — such asjuneau-microservice-jetty— contribute servers, listeners, and servlets through standard@Beandefinitions, rather than via subclassing.
When to use it
Use juneau-microservice when you want a stand-alone executable jar that reads its settings from a config file and manifest. Add juneau-microservice-jetty to serve REST resources.
Example
import org.apache.juneau.microservice.*;
public class MyMicroservice {
public static void main(String[] args) throws Exception {
// Build the microservice from the command-line arguments, start it, and wait for it to stop.
Microservice.create().args(args).build().start().join();
}
}
Options
| Builder method | Use it to |
|---|---|
args(String...) | Pass the command-line arguments |
listener(MicroserviceListener) | React to start, stop and config changes |
Module Name (Renamed in 10.0)
In 10.0 this module was renamed from juneau-microservice-core to juneau-microservice. The Java package
(org.apache.juneau.microservice) is unchanged. See the V10 Migration Guide for the
exact dependency update.
See also
In This Section
4.1.1. Microservice Overview
Juneau microservices are self-contained, deployable REST servers built on top of the Juneau REST
4.1.2. Args
Command-line arguments can be associated with a microservice using the args() method.
4.1.3. Manifest
The Microservice.Builder.manifest(Object)
4.1.4. Config
The following methods can be used to define the configuration for your microservice using the powerful Config API.
4.1.5. VarResolver
The Microservice API incorporates the Simple Variable Language API.
4.1.6. Console Commands
The Microservice API provides support for simple console commands.
4.1.7. Listeners
The lifecycle methods of the Microservice class are non-final so that subclasses can override them. A listener interface offers the same hooks without subclassing.
4.1.8. Inject-Aware Microservice
Starting with 10.0.0, the Microservice
4.1.9. Whole-Microservice Integration Tests (@MicroserviceTest)
@MicroserviceTest is a JUnit 5 extension that boots a whole Microservice — config, lifecycle, and an embedded Jetty server on an ephemeral port — for the duration of a test class, then stops it cleanly. It's the standalone-microservice analog of Spring's @SpringBootTest, and it composes the existing @TestBean mock-bean substrate for collaborator substitution.