Quickstart: Publish/Subscribe
This quickstart showcases how to enable the publish/subscribe pattern using the Pub/Sub 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 pubsub --language python
diagrid dev quickstart --type pubsub --language csharp
diagrid dev quickstart --type pubsub --language javascript
diagrid dev quickstart --type pubsub --language java
After the command executes successfully, the CLI will output the contents of your newly created project including the two App IDs publisher and subscriber and a Diagrid KV Store called pubsub.
Install Dependencies and Run
The diagrid dev run command creates your Catalyst project (if needed), provisions resources (App IDs, Components, Diagrid Pub/Sub service), configures environment variables, and launches your application using the dapr multi-app run file.
- Python
- .NET
- JavaScript
- Java
Create and activate a Python virtual environment:
python -m venv venv
source venv/bin/activate # MacOS/Linux
# Or: venv\Scripts\activate # Windows
Windows users: Use venv\Scripts\Activate.ps1 (PowerShell) or venv\Scripts\activate.bat (Command Prompt). Use conda, pipenv, or your preferred tool if desired.
Install dependencies:
pip install -r ./publisher/requirements.txt && pip install -r ./subscriber/requirements.txt
Install .NET dependencies:
dotnet restore ./publisher && dotnet restore ./subscriber
Install Node dependencies:
npm install --prefix ./publisher && npm install --prefix ./subscriber
Install Maven dependencies:
mvn clean install -f ./publisher && mvn clean install -f ./subscriber
Run the application:
- Python
- .NET
- JavaScript
- Java
diagrid dev run -f dev-python-pubsub.yaml --project dev-python-pubsub
diagrid dev run -f dev-csharp-pubsub.yaml --project dev-csharp-pubsub
diagrid dev run -f dev-js-pubsub.yaml --project dev-js-pubsub
diagrid dev run -f dev-java-pubsub.yaml --project dev-java-pubsub
Ensure the log Connected App ID "subscriber" to localhost:5002 appears before proceeding to the next section.
Call the Publish API
With the quickstart running, test the Publish API using curl or the REST Client extension with the test.rest file.
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 publisher app logs should show an indication that a message was successfully published, and the subscriber app logs should indicate the message was successfully received.

You can also view the published messages using the Diagrid Pub/Sub topic explorer. When the Pending Message Count is 0, it means the subscriber app has successfully processed all messages on the orders topic.

To stop the applications and disconnect the local app connection:
diagrid dev stop
Clean Up ResourcesOptional
If you are not going to continue to use this application, delete the app IDs:
diagrid appid delete publisher
diagrid appid delete subscriber
To delete the entire Catalyst project, including the managed infrastructure resources:
diagrid project delete dev-python-pubsub # or dev-csharp-pubsub, dev-js-pubsub, dev-java-pubsub