Secondbase
A collection of helper tools in the form of Java libraries optionally controlled through command line arguments. The main aim of this project is to provide lightweight integration behind a common flags implementation.
Install
SecondBase is deployed through Maven in The Central Repository.
Maven 'all'
The all
artifact has all the dependencies built into it and provides a convenience class for instantiating everything.
<dependency>
<groupId>com.github.secondbase</groupId>
<artifactId>all</artifactId>
</dependency>
import com.github.secondbase.core.SecondBase;
import com.github.secondbase.core.SecondBaseException;
public final class MyService {
private MyService() {}
public static void main(final String[] args) throws SecondBaseException {
new SecondBase(args, new Flags().loadOpts(MyService.class));
}
}
Maven 'core'
The core
artifact allows for choosing which modules you want. Any of which can be omitted if you do not need the features it provides. This will also lessen the dependency tree and need of dependency management.
<dependency>
<groupId>com.github.secondbase</groupId>
<artifactId>core</artifactId>
</dependency>
import com.github.secondbase.all.SecondBase;
import com.github.secondbase.core.SecondBaseException;
public final class MyService {
private MyService() {}
public static void main(final String[] args) throws SecondBaseException, IOException {
final SecondBaseModule[] modules = {};
new SecondBase(args, modules, new Flags().loadOpts(MyService.class));
}
}
This Java application shows an example http service running SecondBase configured manually with all modules activated. The pom.xml file shows all the dependencies needed.
Below is the list of modules which can be used.
Modules
- consul classes for registering services in Consul
- consul-prometheus-widget register the Prometheus metrics endpoint in consul
- flags for command line argument parsing and secret fetching
- jsonlogging to wrap setting up json logging to stdout
- webconsole to start a standalone webserver
prometheus-webconsole
host a Prometheus metrics endpoint in webconsole
Examples
- Basic use of SecondBase with only Flags: HelloSecondBase
- Using every module available: HelloAll
- Registering a service with Consul: HelloConsul
- Parsing command line arguments through Flags: HelloFlags
- Setting up and using json logging: HelloJsonLogging