kafka-streams-graphviz
Requirements
- Java toolchain (JVM, Gradle, etc.)
- Graphviz toolchain
- Kafka Streams app
How to use
Here, we show how this library can be used to render a graph for your Kafka Streams topology.
Build your Kafka Streams topology
First, one must have a Kafka Streams Topology
available:
StreamsBuilder builder = new StreamsBuilder();
... // This is where one would use builder to define a topology
Topology topology = builder.build();
(see TestKafkaStreamsTopology
for a more complete example)
Describe as graphviz graph
Using the Kafka Streams Topology
one can then use this library to describe this as a graphviz-java
Graph
:
Topology topology = builder.build();
Graph graph = GraphvizTopology
.describe(topology)
.asGraphvizGraph();
Render as DOT, Image, ...
This graphviz-java
Graph
can then be rendered, for example, as a DOT file, or PNG file:
Graph g = GraphvizTopology
.describe(topology)
.asGraphvizGraph();
Graphviz
.fromGraph(g)
.render(Format.DOT)
.toFile(new File("examples/ex1.dot"));
Graphviz
.fromGraph(g)
.render(Format.PNG)
.toFile(new File("examples/ex1.png"));
For TestKafkaStreamsTopology
this yields the following image:
Finetuning with graphviz-java
Further finetuning of the Graph can be done programmatically by extending the Graph
, e.g.:
Graph g = GraphvizTopology
.describe(topology)
.asGraphvizGraph();
Graph graphWithExtraInfo = g.with(
graph()
.graphAttr().with(Rank.inSubgraph(Rank.RankType.SAME))
.with(node("input-topic-1"), node("input-topic-2"), node("input-topic-3"))
);
Graphviz
.fromGraph(graphWithExtraInfo)
.render(Format.DOT)
.toFile(new File("examples/ex2.dot"));
See graphviz-java for more details.
For TestKafkaStreamsTopology
this yields the following image:
Acknowledgements
This project would never be able to exist without the following projects: