Git Product home page Git Product logo

distributed-calculator's Introduction

Distributed Calculator

This demo project is an adaptation of the distributed-calculator tutorial from the beautiful collection of Dapr quickstarts and tutorials. It showcases Fleet as a multi-language IDE and demonstrates features such as smart mode, run configurations, debugging, integration with Git and Docker, remote development, and remote collaboration.

Calculator Screenshot

The original distributed-calculator project demonstrates method invocation and state persistence capabilities of the Dapr engine via a distributed calculator where each operation is powered by a different service written in a different language/framework. In this adaptation, we provide a more extensive list of service implementations:

  • A C++ Crow application, implementing addition and subtraction.
  • A Rust actix_web application, implementing multiplication and division.
  • A Go mux application, implementing addition.
  • A Java Spark application, implementing addition and multiplication.
  • A Kotlin Ktor application, implementing division.
  • A C# ASP.NET 7.0 application, implementing subtraction.
  • A Python flask application, implementing multiplication.
  • A PHP Symfony application, implementing subtraction.
  • A Node Express application, implementing division.

Each backend application listens to its own port and responds to one or several POST requests (/add, /multiply, /subtract, /divide) with a JSON-encoded body like the following:

{
    "operandOne":"52",
    "operandTwo":"34"
}

The result is a single number.

The front-end application consists of a server and a client written in React. Credit goes to ahfarmer for the React calculator.

The diagram below showcases the architecture of the original project:

Architecture Diagram

Prerequisites for Running the Project

  1. Install Dapr CLI
  2. Install .NET SDK 7.0
  3. Install Go
  4. Install Python3 and Pipenv
  5. Install Npm
  6. Install Node
  7. Install Rust
  8. Install PHP and composer
  9. Install cmake and conan
  10. Install Docker
  11. Run ./deps.sh to install additional project dependencies.

Running the Project

  1. Initialize the Dapr runtime by running dapr init. This commands installs the required runtime binaries and launches the Dapr services including Redis and Zipkin in Docker containers.

  2. There are numerous Run Configurations (Run/Run & Debug...) to run frontend and backend applications alongside the Dapr sidecar instances. Alternatively, one can use the ./start-service.sh script:

./start-service.sh frontendapp
./start-service.sh kotlin-calc
  1. Open a browser window and navigate to http://localhost:8080/. When here, different operations can be entered. If running the project from a cloud environment, it may be needed to Forward Port 8080 to a local port (this can be done via the Go to/Actions... menu).

  2. Open the console of the browser (typically accessed with the F12 key) to examine logs that are produced as the calculator is used. Observe that with each button press, logs are generated that indicate state persistence and the various apps that have been contacted to carry out the operation.

  3. Optional: Validate services

To ensure all the backend applications function properly, the Validate Services Run Configuration can be used. This will test all the operations and report if anything is missing. This configuration executes the ./validate-services.sh script. If everything is working correctly, the following output should be seen:

Validated Services

  1. Optional: Check persistent state (powered by Redis)
  • To check the persistent state, the following curl command can be run:
curl -s http://localhost:8080/state

Sample response:

{"operation":null,"service":null,"total":"42","next":null}
  • Another option is to use redis-cli in the Redis Docker container. Open the Docker tool in one of the side panels, find the dapr_redis container, and once selected, open a terminal (the button to do this is located to the right of the container's name and port number).

Sample session in the terminal:

root@a20170d47d09:/data# redis-cli
127.0.0.1:6379> keys *
1) "frontendapp||calculatorState"
127.0.0.1:6379> hgetall "frontendapp||calculatorState"
1) "version"
2) "281"
3) "data"
4) "{\"total\":\"2\",\"next\":\"3\",\"operation\":\"+\",\"service\":\"go\"}"
127.0.0.1:6379>
  1. Cleanup
  • To clean up microservices, use the Stop Services Run Configuration (which executes ./stop-services.sh).
  • To uninstall Dapr and remove its Docker services, use:
    dapr uninstall --all

distributed-calculator's People

Contributors

bravit avatar

Stargazers

AN avatar Leonid Shirmanov avatar Natalie Perret avatar Christopher avatar Ilya Evtushenko avatar

Watchers

 avatar

Forkers

hoofedear

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.