This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch console in repository https://gitbox.apache.org/repos/asf/camel.git
commit 04f9a3b63cdfd8bae71e5cb7a1c0dd20b9b1d202 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Thu Dec 30 13:02:00 2021 +0100 CAMEL-17384: Developer Console SPI --- docs/user-manual/modules/ROOT/nav.adoc | 1 + .../modules/ROOT/pages/camel-console.adoc | 142 +++++++++++++++++++++ 2 files changed, 143 insertions(+) diff --git a/docs/user-manual/modules/ROOT/nav.adoc b/docs/user-manual/modules/ROOT/nav.adoc index 0c9e227..88f4de7 100644 --- a/docs/user-manual/modules/ROOT/nav.adoc +++ b/docs/user-manual/modules/ROOT/nav.adoc @@ -4,6 +4,7 @@ * Resources & Guides ** link:/community/books/[Books] ** xref:building.adoc[Building] +** xref:camel-console.adoc[Camel Developer Console] ** xref:camel-jbang.adoc[Camel JBang] ** xref:camel-maven-plugin.adoc[Camel Maven Plugin] ** xref:camel-component-maven-plugin.adoc[Camel Component Maven Plugin] diff --git a/docs/user-manual/modules/ROOT/pages/camel-console.adoc b/docs/user-manual/modules/ROOT/pages/camel-console.adoc new file mode 100644 index 0000000..a551645 --- /dev/null +++ b/docs/user-manual/modules/ROOT/pages/camel-console.adoc @@ -0,0 +1,142 @@ += Camel Console + +The `camel-console` is available from *Camel 3.15* and newer versions. + +The Camel Developer Console is intended assisting developers and can display +various information about a running Camel application. + +Camel comes with a set of consoles out of the box from `camel-console` and `camel-catalog-console` JARs. +These consoles can display general information about the running JVM and the OS Environment, and of course +Camel related information such as runtime metrics of the Camel routes, and a lot more. + +== Using Camel Console + +The `camel-console` must be added to the classpath, and enabled either via + +[source,java] +---- +CamelContext context = ... +context.setDevConsole(true); +---- + +If using Camel Main / Spring Boot / Quarkus etc then the console can be enabled via +configuration: + +[source,properties] +---- +camel.main.dev-console-enabled = true +---- + +=== Dev Console and Camel JBang + +The Developer Console is easily available when using xref:camel-jbang.adoc[Camel JBang], +by the `--console` argument when running JBang. + +For example to run a Camel route from `foo.yaml` and additional configurations from `myapp.properties` you can run as follows +and have the console started and accessible from `http://localhost:8080/dev` + +[source,bash] +---- +$ jbang CamelJBang@apache/camel run foo.yaml myapp.properties --console +---- + +== Writing Custom Dev Consoles + +To write a custom console, you need to add `camel-console` as dependency, as it comes with the +base class `AbstractDevConsole` which we extend for our console. + +[source,java] +---- +@DevConsole("foo") +public class FooConsole extends AbstractDevConsole { + + public FooConsole() { + super("acme", "foo", "Foolish", "A foolish console that outputs something"); + } + + @Override + protected Object doCall(MediaType mediaType, Map<String, Object> options) { + if (mediaType.TEXT.equals(mediaType)) { + return "Some foolish text here"; + } else { + // json structure + } + } + +} +---- + +The class must be annotated with `DevConsole` and the unique id of the console (must be unique across all consoles). +In the constructor the console specifies which group, id, display title, and description to use. + +The `doCall` method is responsible for gathering the information the console should output. + +=== Supported Media Types + +A console can support any of, or all of the following types: + +- TEXT +- JSON + +The intention for `TEXT` is to be plain/text based that can be outputted in CLI and other low-level tools. + +For `JSON` then the intention is the console outputs a json dataset with key/value pairs that +holds the information, which can be displayed in a custom fashion such as in a web browser, or IDE tool such as VSCode. + +=== Maven Configuration + +To make Camel able to discover custom dev consoles, then the xref:camel-component-maven-plugin.adoc[came-component-maven-plugin] +must be used, such as: + +[source,xml] +---- +<build> + <plugins> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-component-maven-plugin</artifactId> + <version>${camel-version}</version> + <executions> + <execution> + <id>generate</id> + <goals> + <goal>generate</goal> + </goals> + <phase>process-classes</phase> + </execution> + <execution> + <id>generate-postcompile</id> + <goals> + <goal>generate-postcompile</goal> + </goals> + <phase>prepare-package</phase> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>build-helper-maven-plugin</artifactId> + <executions> + <execution> + <phase>generate-sources</phase> + <goals> + <goal>add-source</goal> + <goal>add-resource</goal> + </goals> + <configuration> + <sources> + <source>src/generated/java</source> + </sources> + <resources> + <resource> + <directory>src/generated/resources</directory> + </resource> + </resources> + </configuration> + </execution> + </executions> + </plugin> + </plugins> +</build> +---- +