In this example, you will see how classes are used to represent input and output data of Workflow and Activity Definitions.
If you haven't already started the Translation Microservice used by this exercise, do so in a separate terminal.
- Navigate to the
utilitiesdirectory at the root level of the course - Change directoryies into the
microservice directorycd utilities/microservice
- Compile the microservice
mvn clean compile
- Start the microservice
mvn exec:java -Dexec.mainClass="translationapi.Microservice"
This sample provides an improved version of the translation Workflow used in Temporal 101. The Workflow follows the best practice of using classes to represent input parameters and return values.
Look at the code in the models directory to see how the classes are defined for
the Workflows and Activities. After this, look at the TranslationWorkflow.java
and TranslationWorkflowImpl.java files to see how these values are passed in
and used in the Workflow code. Finally, look at the Starter.java to see how
the input parameters are created and passed into the Workflow.
Now let's take a look at how we used classes to represent input and output data in Activity definitions.
Take a look at the TranslationActivities.java and TranslationActivitiesImpl.java
files to see how the translateTerm function takes in the TranslationActivityInput
class as an input parameter. Also notice how that function returns a
TranslationActivityOutput class for the output.
To run the workflow:
- Ensure that your Translation Microservice is running in a separate. See the prerequisites at the top of this file for instructions.
- In another terminal, start the Worker by running
mvn exec:java -Dexec.mainClass="translationworkflow.TranslationWorker" - In another terminal, execute the Workflow by running
mvn exec:java -Dexec.mainClass="translationworkflow.Starter" -Dexec.args="Mason de"(replaceMasonwith your first name), which should display customized greeting and farewell messages in German.
It's common for a single Workflow Definition to be executed multiple times, each time using a different input. Feel free to experiment with this by specifying a different language code when starting the Workflow. The translation service currently supports the following languages:
de: Germanes: Spanishfr: Frenchlv: Latvianmi: Maorisk: Slovaktr: Turkishzu: Zulu