4.1 KiB
Service Invocation
In this quickstart, you'll create a checkout service and an order processor service to demonstrate how to use the service invocation API. The checkout service uses Dapr's http proxying capability to invoke a method on the order processing service.
Visit this link for more information about Dapr and service invocation.
This quickstart includes one checkout service:
- Node client service
checkout
And one order-processor service:
- Node order-processor service
order-processor
Run all apps with multi-app run template file:
This section shows how to run both applications at once using multi-app run template files with dapr run -f .. This enables to you test the interactions between multiple applications.
- Open a new terminal window and install dependencies for
order-processorandcheckoutapps:
cd ./order-processor
npm install
cd ../checkout
npm install
cd ..
- Run the multi app run template:
dapr run -f .
The terminal console output should look similar to this:
== APP - order-processor == Order received: { orderId: 1 }
== APP - checkout == Order passed: {"orderId":1}
== APP - order-processor == Order received: { orderId: 2 }
== APP - checkout == Order passed: {"orderId":2}
== APP - order-processor == Order received: { orderId: 3 }
== APP - checkout == Order passed: {"orderId":3}
== APP - order-processor == Order received: { orderId: 4 }
== APP - checkout == Order passed: {"orderId":4}
== APP - order-processor == Order received: { orderId: 5 }
== APP - checkout == Order passed: {"orderId":5}
== APP - order-processor == Order received: { orderId: 6 }
== APP - checkout == Order passed: {"orderId":6}
== APP - order-processor == Order received: { orderId: 7 }
== APP - checkout == Order passed: {"orderId":7}
== APP - order-processor == Order received: { orderId: 8 }
== APP - checkout == Order passed: {"orderId":8}
== APP - order-processor == Order received: { orderId: 9 }
== APP - checkout == Order passed: {"orderId":9}
== APP - order-processor == Order received: { orderId: 10 }
== APP - checkout == Order passed: {"orderId":10}
== APP - order-processor == Order received: { orderId: 11 }
== APP - checkout == Order passed: {"orderId":11}
== APP - order-processor == Order received: { orderId: 12 }
== APP - checkout == Order passed: {"orderId":12}
- Stop and clean up application processes
dapr stop -f .
Run a single app at a time with Dapr (Optional)
An alternative to running all or multiple applications at once is to run single apps one-at-a-time using multiple dapr run .. -- npm start commands. This next section covers how to do this.
Run Node order-processor with Dapr
- Open a new terminal window and navigate to
order-processordirectory and install dependencies:
cd ./order-processor
npm install
- Run the Node order-processor app with Dapr:
dapr run --app-port 5001 --app-id order-processor --app-protocol http --dapr-http-port 3501 -- npm start
Run Node checkout with Dapr
- Open a new terminal window and navigate to
checkoutdirectory and install dependencies:
cd ./checkout
npm install
- Run the Node checkout app with Dapr:
dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- npm start
Stop and clean up application processes
dapr stop --app-id checkout
dapr stop --app-id order-processor