-
Notifications
You must be signed in to change notification settings - Fork 43
Examples
The following script compiles the flux runtime.
./build.sh noTests
To run the end-to-end examples, you must have a mysql installation running on your system.
To keep it simple we assume that the root user has create database privileges and works without a password. If these are not the settings on your system, please change setup_db.sh
and configuration.yml
appropriately
Run the following script to setup a skeleton database for use in Flux. Flux has to be built first before running the setup script, as liquibase is used for setting up internally.
./setup_db.sh
We've put up an example to demonstrate the power of flux to run multiple independent tasks concurrently.
For this, please check out class com.flipkart.flux.examples.concurrent.EmailMarketingWorkflow
To run the example workflow, the codebase must be built and the database setup using steps documented above. Then, you can run the workflow using:
cd examples
./run_example.sh com.flipkart.flux.examples.concurrent.RunEmailMarketingWorkflow
You can also run the example from IDE as mentioned in the bottom of this page.
Following is a code snippet from the given example:
for (Email email : emails) {
emailDispatcher.sendEmail(email);
}
When the @Workflow
annotated method is invoked, the client library intercepts the call & further intercepts all calls made to @Task
annotated methods.
This is used to create a state machine representation and submitted to the Flux engine for execution.
In flux, the following state machine is created:
We've put up an example to demonstrate how you can take decisions in your workflow.
For this, please check out class com.flipkart.flux.examples.decision.UserVerificationWorkflow
To run the class, the codebase must be built and the database setup using steps documented above Then, you can run the class using:
cd examples
./run_example.sh com.flipkart.flux.examples.decision.RunUserVerificationWorkflow
Again, the client library intercepts the @Workflow
method and creates the following state machine in the Flux Runtime
The example in code has a lot more documentation explaining how this is achieved.
In a lot of cases, Workflows would need to wait for external events. For example, Seller verifications would require manual intervention from the Customer Support team. Once the seller Id is generated, the workflow would essentially involve notifying customer support and waiting for them to verify the seller.
This scenario is captured in com.flipkart.flux.examples.externalevents.ManualSellerVerificationFlow
To run the class, the codebase must be built and the database setup using steps documented above Then, you can run the class using:
cd examples
./run_example.sh com.flipkart.flux.examples.externalevents.RunManualSellerVerificationWorkflow
The same examples above may be executed in isolated mode like so, for e.g. :
cd examples
run_separate_modes_example.sh com.flipkart.flux.examples.concurrent.RunEmailMarketingWorkflow
To run the example workflow, the codebase must be built and the database setup using steps documented above. Then, you can run the workflow using:
cd examples
./run_example.sh <workflow_class_fqn>
workflow_class_fqn: fully qualified name of main class which triggers user workflow execution at client side
ex: com.flipkart.flux.examples.concurrent.RunEmailMarketingWorkflow
You can start the example workflow from shell script, and to debug you can attach the process in IDE.
cd examples
./run_example.sh <workflow_class_fqn> debug <debug_port_number>
workflow_class_fqn: fully qualified name of main class which triggers user workflow execution at client side
ex: com.flipkart.flux.examples.concurrent.RunEmailMarketingWorkflow
debug_port_number: port on which flux process debugged
Ex: ./run_example.sh com.flipkart.flux.examples.concurrent.RunEmailMarketingWorkflow debug 8888
After that attach a remote debugger in IDE using http://stackoverflow.com/a/30793101 for Intellij, https://dzone.com/articles/how-debug-remote-java-applicat for Eclipse.
Once the database setup is over using the above mentioned setup script, you can run com.flipkart.flux.examples.WorkflowExecutionDemo
class from IDE to run or debug the workflows in local.
Usage: com.flipkart.flux.examples.WorkflowExecutionDemo <module_name> <workflow_class_fqn>
module_name : name of user module in which workflow code is present, for ex: examples
workflow_class_fqn: fully qualified name of main class which triggers user workflow execution at client side
ex: com.flipkart.flux.examples.concurrent.RunEmailMarketingWorkflow
This demo class requires maven to copy dependencies to create a sample deployment unit structure.
If maven is NOT present on the class path pass its absolute location as third argument
for ex: WorkflowExecutionDemo <module_name> <workflow_class_fqn> /opt/apache-maven-3.3.3/bin/mvn
In the Eclipse IDE, this would translate to the following Run Configuration:
Project : examples
Main class : com.flipkart.flux.examples.WorkflowExecutionDemo
Program arguments : examples com.flipkart.flux.examples.externalevents.RunManualSellerVerificationWorkflow /usr/local/bin/mvn
Ensure you set the Working directory to the location you have cloned Flux to. For e.g.
Working directory : /Users/codeninja/Documents/workspace/github/flux
In IntelliJ Idea:
Main class: com.flipkart.flux.examples.WorkflowExecutionDemo
Program arguments: examples com.flipkart.flux.examples.decision.RunUserVerificationWorkflow
Working directory : /Users/codeninja/Documents/workspace/github/flux
Use classpath of module: examples