Git Product home page Git Product logo

ppc-onboarding-temporal's Introduction

Customer Onboarding Temporal Workflow

Workflow Demo using Temporal.io (Spring Boot Example) for Onboarding use case

Sections

  1. What does the Application do?
  2. What is Temporal.io ?
  3. Pre-requisites
  4. Run the application
  5. Invoke the API
  6. View the workflow instance
  7. Running on GKE

What does the Application do?

The workflow application invokes 4 activities in the following sequence 1) Create CustReg Record --> 2) Create Mailer Record --> 3) Create Payment Account --> 4) Set Payment Account Type (ACH, Credit)

Activities 1 & 2 are invoked in sequence as soon as the workflow instance begins. The workflow instance is now awaiting a user click on the application UI, on this signal Activity 3 is invoked. After Activity 3 is completed, the workflow instance is awaiting a user click on the application UI to set the Payment type, on this signal Activity 4 is invoked.

Each Activity or step calls a Rest API and gets a response. The response payload could be used in subsequent activities. If the API call fails (when the REST API is not running for example), the temporal worflow engine persists the state of the activity to retry with a backoff coefficient up to a given number of attempts.

What is Temporal.io ?

Temporal https://github.com/temporalio is an orchestration engine (MIT License) that can be used to orchestrate services at scale.

Pre-requisites to run locally

You must make sure a temporal server is running https://github.com/temporalio/docker-compose#readme

Run the application

Clone the repo https://github.com/vikramspringml/ppc-onboarding-demo.git

Use mvn install clean package spring-boot:run to run the application.

Invoke the API

Invoke the REST API to start the workflow instance using POST http://localhost:8080/start ,Use the POST payload body

{
    "username": "brian",
    "password": "test",
    "secqtn1": "test",
    "secqtn2": "test",
    "contactTitle": "test",
    "contactFName":"fname",
    "contactLName":"lname",
    "contactEmail":"[email protected]"
}

Invoke the REST API to view the latest status of the workflow instance using GET http://localhost:8080/getwfstatus?id=brian

Invoke the REST API to CONTINUE the workflow instance using POST http://localhost:8080/step2 ,Use the POST payload body

{
    "username": "brian",
    "crid": "5678765"
}

Invoke the REST API to view the LATEST status of the workflow instance using GET http://localhost:8080/getwfstatus?id=brian

Invoke the REST API to CONTINUE the workflow instance using POST http://localhost:8080/step3 ,Use the POST payload body

{
    "username": "brian",
    "password": "test",
    "secqtn1": "test",
    "secqtn2": "test",
    "contactTitle": "test",
    "contactFName":"fname",
    "contactLName":"lname",
    "contactEmail":"[email protected]"
}

Invoke the REST API to view the LATEST status of the workflow instance using GET http://localhost:8080/getwfstatus?id=brian

View the workflow instance

Once the API is invoked you can view the workflow instances using the Temporal Web UI

On a web browser, navigate to http://localhost:8088/ to access the Temporal UI to observe the workflow instances.

Running on GKE

The application can be run as a Workflow client and worker using env variable configuration. The workflow client is a REST API invoked application that creates the workflow instance on the Temporal server. The workflow worker is an application that listens to Temporal task queues and performs the activities defined in the workflow.

Manually Create container image for your workflow client and worker

Build and package the code by running mvn

mvn -DskipTests=true clean install spring-boot:repackage

Login to gcloud with your auth

gcloud auth login

Deploy the container to us.gcr.io

gcloud builds submit .
--tag us.gcr.io/{gcp-projectid}/{container-name}

Alternatively - Cloud Build command to Build and create image on GCR.IO

gcloud builds submit .

Deploy to GKE

Run the following commands on cloud shell to authenticate gcloud, authenticate w GKE cluster and add master authorized network

gcloud auth login

gcloud config set project {PROJECT_ID}

gcloud container clusters get-credentials 
${GKE_CLUSTER} --region {GKE_CLUSTER_REGION} 
--project {PROJECT_ID}

gcloud container clusters update {GKE_CLUSTER} 
--region {GKE_CLUSTER_REGION} 
--enable-master-authorized-networks 
--master-authorized-networks $(dig +short myip.opendns.com @resolver1.opendns.com)/32

Apply the GKE Deployments

App containing the API to trigger the workflow

  • Apply workflow API service deployment
kubectl apply -f k8s/service.yaml

Verify your deployment using the deployment name temporal-demo-api

App containing the worker to poll workflow task queue and handle activities

  • Apply workflow worker (Poller) deployment
kubectl apply -f k8s/deployment.yaml

Verify your deployment using the deployment name temporal-demo-worker

Test workflow on GKE

Create port forward for web to view the Temporal Web UI

kubectl port-forward services/temporaltest-web 8088:8088

Navigate to http://localhost:8888 on your browser

Create port forward for temporal-service-api to invoke the workflow

kubectl port-forward services/temporal-demo-api-svc 8080:80

Invoke the API on curl using Invoke the API

Install Temporal using Cloud SQL PostGRES Database with Custom Helm Chart

See instructions here

ppc-onboarding-temporal's People

Contributors

vikramspringml avatar rvprksh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.