Once you made Mutiny available to your classpath, you can start writing code. Let’s start with this simple program:
This program prints:
Dissecting the pipeline#
What’s interesting is how this message is built. We described a processing pipeline taking an item, processing it and finally consuming it.
First, we create a
Uni, one of the two types with
Multi that Mutiny provides.
Uni is a stream emitting either a single item or a failure.
Here, we create a
Uni emitting the
This is the input of our pipeline.
Then we process this item:
- we append
" mutiny", then
- we make it an uppercase string.
This forms the processing part of our pipeline, and then we finally subscribe to the pipeline.
This last part is essential. If you don’t have a final subscriber, nothing is going to happen. Mutiny types are lazy, meaning that you need to express your interest. If you don’t, the computation won’t even start.
If your program doesn’t do anything, verify that you didn’t forget to subscribe!
Mutiny uses a builder API!#
Another important aspect is the pipeline construction.
Appending a new stage to a pipeline returns a new
The previous program is equivalent to:
It is fundamental to understand that this program is not equivalent to:
This program just prints
">> hello", as it does not use the appended stages and the final subscriber consumes the first
Mutiny APIs are not fluent and each computation stage returns a new object.