Skip to content

nagl-stripe/samples-java

 
 

Repository files navigation

Temporal Java SDK Samples

FOSSA Status

This repository contains sample Workflow applications that demonstrate various capabilities of Temporal using the Java SDK.

Table of Contents

How to use

  1. Clone this repository:

    git clone https://github.com/temporalio/samples-java
    cd samples-java
    
  2. Build the examples and run tests:

    ./gradlew build
    
  3. You need a locally running Temporal Server instance to run the samples. We recommend a locally running version of the Temporal Server managed via Docker Compose:

    git clone https://github.com/temporalio/docker-compose.git
    cd  docker-compose
    docker-compose up
    

Note that for the "listworkflows" example you need to have the Elasticsearch feature enabled on the Temporal Server side. To do this you can run locally with:

   git clone https://github.com/temporalio/docker-compose.git
   cd  docker-compose
   docker-compose -f docker-compose-cas-es.yml up

Alternatively you could install the Temporal Server on Kubernetes / Minicube using the Temporal Helm charts. Note that in this case you should use the Temporal CLI (tctl) tool to create a namespace called "default":

   tctl --ns default n re

Temporal Web UI

The Temporal Server running in a docker container includes a Web UI.

Connect to http://localhost:8088.

If you have deployed the Temporal Server on Kubernetes using Helm Charts, you can use the kubectl command-line tool to forward your local machine ports to the Temporal Web UI:

    kubectl port-forward services/temporaltest-web 8088:8088
    kubectl port-forward services/temporaltest-frontend-headless 7233:7233

With this you should be able to access the Temporal Web UI with http://localhost:8088.

Samples directory

The following section lists all available samples. Click on the sample link to view the README, which contains instructions on how to run them.

Each sample has an associated unit test which demonstrates the use of the Temporal Java SDK testing API. All tests are available under src/test/java

Hello samples

  • Hello: This sample includes a number of individual Workflows that can be executed independently. Each one demonstrates something specific.

Scenario-based samples

  • File Processing Sample: Demonstrates how to route tasks to specific Workers. This sample has a set of Activities that download a file, processes it, and uploads the result to a destination. Any Worker can execute the first Activity. However, the second and third Activities must be executed on the same host as the first one.

  • Booking SAGA: Demonstrates Temporals take on the Camunda BPMN "trip booking" example.

  • Money Transfer: Demonstrates the use of a dedicated Activity Worker.

  • Money Batch: Demonstrates a situation where a single deposit should be initiated for multiple withdrawals. For example, a seller might want to be paid once per fixed number of transactions. This sample can be easily extended to perform a payment based on more complex criteria, such as at a specific time or an accumulated amount. The sample also demonstrates how to Signal the Workflow when it executes (Signal with start). If the Workflow is already executing, it just receives the Signal. If it is not executing, then the Workflow executes first, and then the Signal is delivered to it. Signal with start is a "lazy" way to execute Workflows when Signaling them.

API demonstrations

  • Updatable Timer: Demonstrates the use of a helper class which relies on Workflow.await to implement a blocking sleep that can be updated at any moment.

  • Workflow Interceptor: Demonstrates how to create and register a simple Workflow Interceptor.

  • List Workflows: Demonstrates the use of custom search attributes and ListWorkflowExecutionsRequest with custom queries.

  • Payload Converter: Demonstrates the use of a custom payload converter.

IDE Integration

IntelliJ

It is possible to run the samples from the command line, but if you prefer IntelliJ here are the import steps:

  • Navigate to File->New->Project from Existing Sources.
  • Select the cloned directory.
  • In the Import Project page, select Import project from external model
  • Choose Gradle and then click Next
  • Click Finish.

About

Temporal Java SDK samples

Resources

License

Unknown, Unknown licenses found

Licenses found

Unknown
LICENSE.txt
Unknown
license-header.txt

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 99.8%
  • Dockerfile 0.2%