In this quickstart, you'll run a publisher and subscriber application on Catalyst Cloud. You will learn how to:
- Provision a Catalyst project with a managed message broker using the Diagrid CLI.
- Publish messages to a topic and receive them in a subscriber application using the Dapr Pub/Sub API.
- Inspect published messages in the Catalyst web console.
---
title: Publisher and Subscriber Apps connected to Catalyst via Pub/Sub
---
flowchart LR
APP1(Publisher App)
subgraph Catalyst
APPID1(ID: publisher)
BROKER@{ shape: das, label: "Message broker" }
APPID2(ID: subscriber)
end
APP2(Subscriber App)
APP1-->APPID1
APPID1-.->BROKER
BROKER-.->APPID2
APPID2-->APP2
Before you proceed, ensure you have the following prerequisites installed.
Authenticate to Diagrid Catalyst using the following command:
diagrid loginThis command opens a new browser window where you'll be shown a confirmation code that should match the code in your terminal. Confirm the code, and if you're not logged into Catalyst, you'll be redirected to login.
Confirm your user details are correct using the following command:
diagrid whoamiThe expected output contains the name of the organization, your user name, and the Catalyst API endpoint.
Clone the quickstart code from GitHub:
git clone https://github.com/diagridio/catalyst-quickstartsNavigate to the quickstart directory:
macOS/Linux:
cd catalyst-quickstarts/pubsub/javascriptWindows:
cd catalyst-quickstarts\pubsub\javascriptInstall the dependencies for both the publisher and subscriber applications.
npm install --prefix ./publisher && npm install --prefix ./subscriberThe diagrid dev run command creates your Catalyst project, provisions resources (apps, Diagrid Pub/Sub service and topic), configures environment variables, and launches your application connected to Catalyst Cloud.
diagrid dev run -f pubsub-quickstart.yaml --project pubsub-quickstart --approveTip: Wait a few seconds until you see the logs
Connected App ID "publisher" to http://localhost:5001andConnected App ID "subscriber" to http://localhost:5002in the terminal before proceeding, to ensure both applications are up and running.
With the quickstart running, test the Pub/Sub API by publishing a message and verifying it was received by the subscriber.
Open a new terminal and publish an order message to the orders topic:
macOS/Linux (curl):
curl -i -X POST http://localhost:5001/order -H "Content-Type: application/json" -d '{"orderId":1}'Windows (PowerShell):
Invoke-RestMethod -Method Post -Uri "http://localhost:5001/order" -ContentType "application/json" -Body '{"orderId":1}'Any OS (VS Code REST Client): open test.rest and click Send Request above the request. Requires the REST Client extension.
The expected response is 201 Created with this body:
{"id":1,"message":"Message published successfully","topic":"orders"}In the diagrid dev run terminal, the publisher app logs should indicate a message was successfully published, and the subscriber app logs should show the message was received on its /neworder route.
Open the Catalyst Cloud web console and navigate to the Pub/Sub topic explorer (Resources > Managed Pub/Sub). When the Pending Message Count for the orders topic reaches 0, the subscriber app has successfully processed all messages.
Press CTRL+C in the terminal that runs diagrid dev run to stop the application and disconnect from Catalyst Cloud.
To delete the entire project and all provisioned resources:
diagrid project delete pubsub-quickstartIn this quickstart you:
- Logged in to Catalyst and provisioned a managed Pub/Sub project with a single CLI command (
diagrid dev run). - Published a message to a topic and verified it was received by a subscriber application.
- Inspected message delivery status using the Catalyst Pub/Sub topic explorer.
Catalyst handled message brokering, topic management, and delivery guarantees automatically — no infrastructure to manage.
- Explore the Dapr API SDK guides to integrate Pub/Sub messaging into your own applications.
- Try the State Management quickstart to add persistent storage to your application.
- Read the full Publish/Subscribe quickstart docs.
- Browse all Catalyst quickstarts in this repository.