{title:'Console Commands', created:'8.0.0'}

The Microservice API provides support for simple console commands.

| public static void main(String[] args) { | Microservice | .create() | .args(args) | .build() | .start() | .startConsole() // Start console. | .join() | ; | }

When started, the console renders the following output:

| Running class 'Microservice' using config file 'my-microservice.cfg'. | | List of available commands: | exit -- Shut down service | restart -- Restarts service | help -- Commands help | | >

The builder methods for controlling the console are as follows:

By default, the supported commands are pulled from the configuration file:

| #======================================================================================================================= | # Console settings | #======================================================================================================================= | [Console] | | enabled = true | | # List of available console commands. | # These are classes that implements ConsoleCommand that allow you to submit commands to the microservice via | # the console. | # When listed here, the implementations must provide a no-arg constructor. | # They can also be provided dynamically by overriding the Microservice.createConsoleCommands() method. | commands = | org.apache.juneau.microservice.console.ExitCommand, | org.apache.juneau.microservice.console.RestartCommand, | org.apache.juneau.microservice.console.HelpCommand

New commands can be added by adding them to the configuration file, or programmatically using the {@link oaj.microservice.Microservice.Builder#consoleCommands(ConsoleCommand...) consoleCommands(ConsoleCommand...)} builder method.

The API for defining console commands is shown below:

By default, the console input and output are taken from {@link java.lang.System#in} and {@link java.lang.System#out}. These can be overridden using the {@link oaj.microservice.Microservice.Builder#console(Scanner,PrintWriter) console(Scanner,PrintWriter)} method.