Diagram

Since Camel 4.21

The Diagram module provides route diagram rendering capabilities for Apache Camel routes. It can generate visual route diagrams as PNG images representations from route structure data.

Features

  • Render route diagrams as PNG images with colored nodes and scope boxes

  • Support for all Camel EIPs: choice, doTry/doCatch, filter, split, loop, multicast, and more

  • Scope boxes visually group branching and scoping EIPs

  • Multiple color themes: dark, light, transparent, or custom

Usage

As a library

Add the camel-diagram dependency to your project:

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-diagram</artifactId>
</dependency>

Using Camel Java API

You can use the diagram render with Camel based APIs such as:

RouteDiagramDumper dumper = PluginHelper.getRouteDiagramDumper(context);
BufferedImage image = dumper.dumpRoutesAsImage("*", RouteDiagramDumper.Theme.DARK);

Using standalone Java API

Then use the API to render diagrams:

import org.apache.camel.diagram.*;
import org.apache.camel.diagram.RouteDiagramLayoutEngine.*;
import org.apache.camel.diagram.RouteDiagramRenderer.*;

// Parse route structure from JSON
List<RouteInfo> routes = RouteDiagramHelper.parseRoutes(jsonObject);

// Layout and render
RouteDiagramLayoutEngine engine = new RouteDiagramLayoutEngine();
RouteDiagramRenderer renderer = new RouteDiagramRenderer();

LayoutRoute lr = engine.layoutRoute(routes.get(0), RouteDiagramLayoutEngine.PADDING);
DiagramColors colors = DiagramColors.parse("dark");
BufferedImage image = renderer.renderDiagram(List.of(lr), lr.maxY + RouteDiagramLayoutEngine.V_GAP, colors);

// Save to file
ImageIO.write(image, "PNG", new File("diagram.png"));

With Camel JBang

The diagram rendering is used by the camel cmd route-diagram command in Camel JBang:

camel cmd route-diagram MyRoute.java

Color Themes

The following built-in themes are available:

  • dark - dark background (default)

  • light - light background

  • transparent - transparent background

Custom colors can be specified using the format:

bg=#1e1e1e:from=#2e7d32:to=#1565c0:eip=#8957e5:choice=#d29922

Color values can be #hex codes or ANSI color names (e.g., seagreen, steelblue).

To use dark theme

camel cmd route-diagram MyRoute.java --theme=dark