Quickstart: Service Invocation
This quickstart showcases how to enable the request-reply pattern using the Service Invocation API.
Prerequisites
Before you proceed, ensure you have the following prereqs installed.
- Python
- .NET
- JavaScript
- Java
Log in to Catalyst
Authenticate to Diagrid Catalyst using the following command:
diagrid login
Confirm your organization and user details are correct:
diagrid whoami
Clone quickstart code
Clone the quickstart code from the Diagrid Labs GitHub repository and navigate to the appropriate directory:
- Python
- .NET
- JavaScript
- Java
diagrid dev quickstart --type invoke --language python
diagrid dev quickstart --type invoke csharp
diagrid dev quickstart --type invoke --language javascript
diagrid dev quickstart --type invoke --language java
Run quickstart application
To run the quickstart locally, use the diagrid dev run
command. This command uses the dapr multi-app run file in the root of the code directory to:
- Provision a Catalyst project: If the project does not exist, the command will create a new project
- Create resources: Creates the necessary resources on Catalyst such as App IDs, Components, and Diagrid Pub/Sub or KV Store managed services
- Launch the quickstart applications: Locates the code directories using the values specified for
workDir
and launches each application using the app command inputs - Inject environment variables: Configures the Dapr client to talk to Catalyst using the
client
App ID API token - Establish Catalyst connectivity: Creates a private dev tunnel for the
server
application on the specifiedappPort
, which will route all traffic destined for theserver
App ID to the local port where the code is running
For additional details on the Catalyst local development experience, read Develop Locally with Catalyst APIs.
- Python
- .NET
- JavaScript
- Java
Install python dependencies in a virtual environment.
This quickstart uses the venv module to create the virtual environment. Please feel free to adapt if you prefer to use conda, pipenv, or another alternative.
python -m venv venv
- MacOS
- Linux
- Windows
If you are using MacOS, start the virtual environment with the following command:
source venv/bin/activate
Don't forget to close your virtual environment with deactivate
when done with the quickstart
If you are using Linux, start the virtual environment with the following command:
source venv/bin/activate
Don't forget to close your virtual environment with deactivate
when done with the quickstart
If you are using PowerShell on Windows, start the virtual environment with the following command:
venv/Scripts/Activate.ps1
If you are using the Command Prompt on Windows, start the virtual environment with the following command:
venv/Scripts/activate.bat
If running in the Windows Command Prompt, don't forget to close your virtual environment with venv/Scripts/deactivate.bat
when done with the quickstart
Install the python packages required by each service:
pip install -r ./client/requirements.txt && pip install -r ./server/requirements.txt
Restore .NET package dependencies required by each service:
dotnet restore ./client && dotnet restore ./server
Install node packages and dependencies required by each service:
npm install --prefix ./client && npm install --prefix ./server
Download and install maven dependencies required by each service:
mvn clean install -f ./client && mvn clean install -f ./server
Run your applications and connect the server
App ID to the local server app using the following command.
- Python
- .NET
- JavaScript
- Java
diagrid dev run -f dev-python-invocation.yaml --project dev-python-invocation
diagrid dev run -f dev-csharp-invocation.yaml --project dev-csharp-invocation
diagrid dev run -f dev-js-invocation.yaml --project dev-js-invocation
diagrid dev run -f dev-java-invocation.yaml --project dev-java-invocation
Ensure the log Connected App ID "server" to localhost:5002
appears before proceeding to the next section.
Interact with Catalyst APIs
With your applications now successfully running, it's time to test the Service Invocation API. Use the curl command below or take advantage of the REST Client extension using Visual Studio Code with the test.rest
file in the root folder of the repo.
Open a new terminal and execute the following curl command:
curl -i -X POST http://localhost:5001/order -H "Content-Type: application/json" -d '{"orderId":1}'
Upon successful execution, the server app should indicate the request was successfully received and the client app logs should output the invocation was successful.
To stop the local applications and disconnect the local app connection for the server
App ID, run:
diagrid dev stop
Clean up resources
If you are not going to continue to use this application, you can delete the resoures using the following commands:
diagrid appid delete client
diagrid appid delete server
If you want to delete the entire Catalyst project, including the managed infrastructure resources, run the diagrid project delete
command.